main = Plot.plot({
aspectRatio: 1,
r: {
type: "sqrt",
domain: d3.extent(
data,
(d) => d.total_health_care_expenditure_euro_per_capita
),
range: [5, 20]
},
marks: [
Plot.gridX({ stroke: "#222", strokeOpacity: 0.05 }),
Plot.gridY({
stroke: "#222",
strokeOpacity: 0.05
}),
Plot.axisX({
label: "Curative care beds",
stroke: "#222",
strokeOpacity: 0.05
}),
Plot.axisY({
label: "Psychiatric care beds",
stroke: "#222",
strokeOpacity: 0.2
}),
Plot.ruleX([0], { stroke: "#222", strokeOpacity: 0.2 }),
Plot.ruleY([0], { stroke: "#222", strokeOpacity: 0.2 }),
Plot.linearRegressionY(data, {
x: "curative_care_beds_in_hospitals_per_100000",
y: "psychiatric_care_beds_in_hospitals_per_100000",
stroke: "#222",
strokeDasharray: "6px 6px",
fill: "none"
}),
Plot.dot(data, {
x: "curative_care_beds_in_hospitals_per_100000",
y: "psychiatric_care_beds_in_hospitals_per_100000",
r: (d) => d.total_health_care_expenditure_euro_per_capita,
fill: (d) => colorScale(d.total_health_care_expenditure_euro_per_capita),
fillOpacity: 0.6,
stroke: "#222",
strokeWidth: 0.5
}),
(index, scales, channels, dimensions, context) => {
doAnnotation(context.ownerSVGElement, {
note: {
title: minCountry[0].geoLabel,
label: `Spends the least on health care in the EU with ${toEuroString(
minCountry[0].total_health_care_expenditure_euro_per_capita
)}`
},
x:
scales.x(minCountry[0].curative_care_beds_in_hospitals_per_100000) -
8,
y:
scales.y(
minCountry[0].psychiatric_care_beds_in_hospitals_per_100000
) + 2,
dy: 50,
dx: -75,
color: "#222",
connector: {
type: "curve",
points: 1,
points: [[-50, 25]]
}
});
doAnnotation(context.ownerSVGElement, {
note: {
title: maxCountry[0].geoLabel,
label: `Spent ${toEuroString(
maxCountry[0].total_health_care_expenditure_euro_per_capita
)} on health`
},
x: scales.x(maxCountry[0].curative_care_beds_in_hospitals_per_100000),
y:
scales.y(
maxCountry[0].psychiatric_care_beds_in_hospitals_per_100000
) -
scales.r(
maxCountry[0].total_health_care_expenditure_euro_per_capita
) -
8,
dy: -100,
dx: 0,
color: "#222"
});
const euAverage = countryDataMap.get("EU27_2020");
doAnnotation(context.ownerSVGElement, {
note: {
label: "European average (2020)",
wrap: 400
},
x: scales.x(euAverage.curative_care_beds_in_hospitals_per_100000) + 4,
y:
scales.y(euAverage.psychiatric_care_beds_in_hospitals_per_100000) -
scales.r(euAverage.total_health_care_expenditure_euro_per_capita) -
4,
dy: -150,
dx: 50,
color: "#222"
});
}
],
height: size.height - 64 - 32, // Update canvas height
width: size.width, // Update canvas width
margin: 0, // Update margins
marginTop: margins.top,
marginBottom: margins.bottom,
marginLeft: margins.left,
marginRight: margins.right
})