Public
Edited
Jun 11, 2023
3 stars
Insert cell
Insert cell
HHplans.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
HHplans.csv
SELECT
plan,
SUM(mon+tue+wed+thu+fri+sat+sun) AS total_km
FROM HHplans
GROUP BY plan;

Insert cell
categoryChart = Plot.plot({
marks: [
Plot.barX(
plan_mileage,
Plot.groupY(
{ x: "sum" },
{
x: "total_km",
y: "plan",
fill: "plan", // color by the category
sort: { y: "x", reverse: true, limit: 20 }
}
)
),
Plot.ruleX([0])
],
marginLeft: 200,
marginRight: 100
})
Insert cell
HHplans.csv
SELECT
plan,
week,
total_distance,
ROUND((total_distance - lag(total_distance, 1, 0) OVER (PARTITION BY plan ORDER BY plan,week))*100/total_distance,0) AS pct_change
FROM (
SELECT
plan,
week,
SUM(mon+tue+wed+thu+fri+sat+sun) AS total_distance
FROM HHplans
GROUP BY plan, week
ORDER BY plan, week
) AS t
Insert cell
hhplans
Type SQL, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
style: "overflow: visible;",
color: {legend: true},
y: {grid: true},
marks: [
Plot.ruleY([0]),
Plot.line(weekly_mileage, {
x: "week",
y: "total_distance",
stroke: "plan"
}),
Plot.text(weekly_mileage, {
filter:(d) => d.pct_change>20 && d.pct_change<100,
x: "week",
y: "total_distance",
stroke: "plan",
text: (d) => `+${d.pct_change}%`,
dy: -5,
lineAnchor: "bottom",
fontWeight:'lighter',
fontSize:9,
strokeWidth:0.7
})
],
y: {label: "Distance (km)"}
});
Insert cell
HHplans.csv
-- slow run
SELECT
1 AS pace,
plan,
SUM(tue+thu+fri) AS weekly_slow_distance
FROM HHplans
GROUP BY plan;
-- SELECT
-- wed_pace AS pace,
-- plan,
-- SUM(wed) AS weekly_distance
-- FROM HHplans
-- GROUP BY plan, wed_pace;

Insert cell
viewof plan = Inputs.select(plans, {label: "plan"})
Insert cell
Plot.plot({
marks: [
Plot.rectY(plan, Plot.binX({y: "count"}, {x: "total_distance", fill:"plan"})),
Plot.ruleY([0])
],
color: {
legend: true
},
x: {
domain: [0, 100]
}
})
Insert cell
plans = d3.group(data, d => d.plan)
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