Public
Edited
Jan 21, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
columns = Object.keys(data[0]);
Insert cell
Insert cell
dataGroups = d3.group(selectedRows, d=>d[groupBy])
Insert cell
testData = {
let testData = [];
dataGroups.forEach((values, keys) => {
testData.push([keys, d3.mean(values.map( val => val[colToShow] )), d3.deviation(values.map( val => val[colToShow] ))])
})

return testData;
}
Insert cell
viewof groupvals = Inputs.select(data.map(d => d[groupBy]), {sort: true, unique: true, multiple:true});

Insert cell
viewof separate = Inputs.toggle({label: "Separate plots"})
Insert cell
viewof statsTable = Inputs.table(testData,{
header:["name", "mean", "sd"],
maxWidth:300})
Insert cell
viewof graphResult = {
if (separate) {
return Plot.plot({
grid: true,
x: {
domain: [0, 1]
},
y: {
label: null
},
facet: {
data:selectedRows,
y:groupBy,
},
marks: [
Plot.rectY(selectedRows, Plot.binX({y: "count"}, {x: colToShow, fill: groupBy})),
Plot.ruleY([0])
]
})
} else {
return Plot.plot({
grid: true,
x: {
domain: [0, 1]
},
marks: [
Plot.rectY(selectedRows, Plot.binX({y: "count"}, {x: colToShow, fill: groupBy, mixBlendMode: "multiply"})),
Plot.ruleY([0])
]
})
}
}
Insert cell
data = { // this is a JS Array of Objects; the key-value pairs consist of the column headers and the cell data
let names =[];
const spreadsheet = await d3.tsv(url).then(data => data.forEach(d => names.push(d))); // d3.tsv returns a Promise
return names;
}
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