Public
Edited
Jun 17, 2023
Insert cell
Insert cell
Plot.plot({
inset: 10,
width: 1200,
marks: [
Plot.frame({ stroke: "#eee" }),
Plot.axisX({
label: xLabel,
ticks: 5,
tickFormat: "$.0s",
grid: true
}),
Plot.gridX({ ticks: 5 }),
Plot.axisY({
label: "Healthcare expenditure as fraction of GDP",
tickFormat: "%"
}),
Plot.gridY(),
Plot.axisFx({ label: "Year" }),
Plot.linearRegressionY(data, {
...channels,
filter: (d) =>
d.population >= 1e6 &&
["Saudi Arabia", "Switzerland", "Ireland", "United States"].indexOf(
d.country
) < 0,
stroke: "#ff7f0e" // tableau10 orange
}),
Plot.dot(data, { fx: "year", x: "gpc", y: "hpg" }),
Plot.text(data, {
filter: (d, i) => d.year === "1990" && d.country === "United States", // arbitrary country to get one tooltip
fx: "year",
x: { value: 2.32e4 },
y: { value: 0.085 },
text: (d) =>
"Regression performed on countries with population at least 1M, excluding U.S., Saudi Arabia, Luxembourg, and Ireland.",
...tooltipStyle,
textAnchor: "start",
lineAnchor: "bottom",
lineWidth: 24,
fontStyle: "italic",
fill: "black",
stroke: "white"
}),
Plot.tip(data, {
filter: (d) => d.country === "United States" && d.year === "2020",
...channels,
anchor: "top-left",
title: tooltipTitle,
...tooltipStyle
}),
Plot.tip(data, {
filter: (d) => d.country === "United States" && d.year !== "2020",
...channels,
anchor: "bottom-left",
title: tooltipTitle,
...tooltipStyle
}),
Plot.tip(
data,
Plot.pointer({
filter: (d) => d.country !== "United States",
...channels,
title: tooltipTitle,
...tooltipStyle
})
)
]
})
Insert cell
tooltipStyle = ({ lineHeight: 1.1, textPadding: 6 })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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