Public
Edited
Jun 26, 2023
8 stars
Insert cell
Insert cell
Insert cell
svg`
<svg width="${size.width}" height="${size.height}">
<g style="font-family: Verdana">
<text x="0" y="0" fill="#222" style="font-weight: bold; alignment-baseline: hanging; font-size: 24px;">
Healthcare beds in the EU, 2019
</text>
<text x="0" y="32" fill="#222" style="alignment-baseline: hanging; font-size: 16px;">
Expenditure has no major impact on what type of beds are prioritesed
</text>
</g>
<g transform="translate(0,${64})">
${main}
</g>

<g transform="translate(0,${size.height - 4})" style="font-family: Verdana">
<text x="0" y="0" fill="#707070" style="">
Source: Eurostat
</text>
<text x="${
size.width
}" y="0" fill="#707070" style="font-size: 16px; font-style: italic; text-anchor: end;">
explained.media

</text>
</g>
</svg>`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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
})
Insert cell
Insert cell
Insert cell
data = FileAttachment("data (1).json").json()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3_annotation = require("https://cdnjs.cloudflare.com/ajax/libs/d3-annotation/2.5.0/d3-annotation.min.js")
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