Published
Edited
Sep 17, 2022
1 fork
Insert cell
# N3C Data Exploration
Insert cell
Insert cell
Insert cell
Insert cell
function parseCategoryData(data) {
let stackVals = new Set();
//Create set of categories to make stacks from
for(let index = 0; index < data.length; index++) {
if(data[index].severity_type != 'Unavailable')
stackVals.add(data[index].severity_type);
}
return Array.from(stackVals);
}
Insert cell
stackVals = parseCategoryData(results);
Insert cell
function prepareDataForStackedBarChart(data, categories) {
//Declare preparedData object (will be array of JSONs)
let preparedData = [];
for(let categoryIndex = 0; categoryIndex < categories.length; categoryIndex++) {
//Store x-values for each JSON trace created
let x_vals = [];
//Stores y-values for each JSON trace created
let y_vals = [];
for(let index = 0; index < data.length; index++) {
if(data[index].severity_type == categories[categoryIndex] && data[index].smoking_status != 'Unknown') {
x_vals.push(data[index].smoking_status);
y_vals.push(data[index].num_patients);
}
}
//Create individual trace object
let curTrace = {x:x_vals, y:y_vals, name:categories[categoryIndex], type:'bar'};
preparedData.push(curTrace);
}
return preparedData;
}
Insert cell
Insert cell
Insert cell
Insert cell
div2 = {
let layout = {barmode: 'stack', yaxis:{
type: 'log',
autorange: true}};
const div = DOM.element('testPlot')
Plotly.newPlot(div, preparedData, layout);
return div
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more