Published
Edited
Jul 30, 2022
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
athletes = FileAttachment("athletes.csv").csv({typed: true})
Insert cell

selectedAthletes = athletes.filter(d => sport.includes(d.sport))
Insert cell
testSportsData = {
let testSportsData = [];
sportsDataGroups.forEach((values, keys) => {
testSportsData.push([keys, d3.mean(values.map( val => val.height )), d3.deviation(values.map( val => val.height ))])
})

return testSportsData;
}
Insert cell
sportsDataGroups = d3.group(selectedAthletes, d=>d.sport)
Insert cell
viewof sport = Inputs.select(athletes.map(d => d.sport), {sort: true, unique: true, label: "sport", multiple:true});

Insert cell
viewof separate = Inputs.toggle({label: "Separate plots"})
Insert cell
viewof statsTable = Inputs.table(testSportsData,{
header:["name", "mean", "sd"],
maxWidth:300})
Insert cell
viewof graphResult = {
if (separate) {
return Plot.plot({
grid: true,
x: {
domain: [1.3, 2.2]
},
y: {
label: null
},
facet: {
data:selectedAthletes,
y:"sport",
},
marks: [
Plot.rectY(selectedAthletes, Plot.binX({y: "count"}, {x: "height", fill: "sport"})),
Plot.ruleY([0])
]
})
} else {
return Plot.plot({
grid: true,
x: {
domain: [1.3, 2.2]
},
marks: [
Plot.rectY(selectedAthletes, Plot.binX({y: "count"}, {x: "height", fill: "sport", mixBlendMode: "multiply"})),
Plot.ruleY([0])
]
})
}
}
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