Public
Edited
Jun 19, 2024
Insert cell
Insert cell
mlb_homeruns_stats = await FileAttachment("mlb_homeruns.csv").csv({typed:true});
Insert cell
viewof filter_date_select = (Inputs.select(d3.group(mlb_homeruns_stats, d => d.year), {value: 2024, sort: true, label: "MLB Season"}));
Insert cell
Plot.plot({
caption: "Home runs last 4 years",
marginLeft:100,
marginRight:50,
width,
x: {
grid: true,
label: "# Home Runs"
},
y: {
label: null
},
color: {
//type: "categorical",
domain: ["Los Angeles Dodgers", "Minnesota Twins", ],
range: ["#0A5794", "#D21F4E"],
//scheme: "BuRd",
//label: "Signed Abortion Bills (%)",
legend: true
},
marks: [
Plot.barX(filter_date_select, {x: "homeRuns", y: "playerName", fill: "currentTeam", tip: true, sort: {y: "x", reverse: true}}),
Plot.text(filter_date_select, {x:"homeRuns", y: "playerName", text: "homeRuns", textAnchor: "start", dx: 10}),
Plot.ruleX([0])
]
})
Insert cell
groupYears = d3.group(mlb_homeruns_stats, (d) => d.year.toString())
Insert cell
viewof filter = Inputs.select(
groupYears,
{ value: groupYears.get("2024"), sort: true, label: "MLB Season" }
)
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