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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more