Public
Edited
Mar 28, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
game
X
playerFullName
Y
OBP
Color
Size
Facet X
pos
Facet Y
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
// data = await d3.json(
// "https://project.trumedianetworks.com/api/mlb/dataviz-data-by-game/0",
// {
// headers: new Headers({
// accept: "application/json",
// tempToken: "01ffb537-7927-4b0d-a2d2-fba9382647b1"
// })
// }
// )
Insert cell
data.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
data
X
Y
BA
Color
Size
Facet X
win
Facet Y
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
data
X
date
Y
PA
Color
home
Size
Facet X
Facet Y
Mark
bar
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
color: { legend: true, scheme: "RdYlBu" },
marks: [
Plot.barY(data, { x: "date", y: "PA", fill: "home", tip: true }),
Plot.ruleY([0])
]
})
Insert cell
d3.extent(data, d=>d.date)
Insert cell
data
X
home
Y
Color
home
Size
Facet X
win
Facet Y
Mark
bar
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
// Plot.plot({
// marks: [
// Plot.frame({ strokeOpacity: 0.1 }),
// Plot.ruleX([0]),
// Plot.dot(
// data,
// Plot.binY(
// { x: "count" },
// { fx: "playerFullName", fy: "opponent", y: "HR", tip: true }
// )
// )
// ]
// })

Insert cell
Insert cell
Insert cell
first_100
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
median_avg.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
{
// Usage example
const top10ByOpponent = getTopNByOpponent(data, "BB_num_mean", 10);

return top10ByOpponent;
}
Insert cell
function getTopNByOpponent(data, column, n) {
// Group data by opponent
const groupedData = d3.group(data, (d) => d.opponent);

// Get top N players with the highest value for the specified column for each opponent
return Array.from(groupedData, ([opponent, players]) => {
return {
opponent,
topN: players.sort((a, b) => b[column] - a[column]).slice(0, n)
};
});
}
Insert cell
Insert cell
Insert cell
video = FileAttachment("video.json").json()
Insert cell
project1 = FileAttachment("project@1.json").json()
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