Plot.plot({
x: {
axis: "top",
grid: true,
tickSize: 0,
tickFormat: d => d.replace(/ COVID-19 deaths/, ""),
label: "COVID-19 deaths (thousands)"
},
y: { nice: true, axis: null },
marginBottom: 10,
marks: [
Plot.link([0, 1e6], {
x1: () => "Reported COVID-19 deaths",
x2: () => "Total COVID-19 deaths",
y1: d => d,
y2: d => d,
strokeOpacity: 0.1,
strokeDasharray: [4, 4]
}),
linkText(data, {
x1: () => "Reported COVID-19 deaths",
x2: () => "Total COVID-19 deaths",
y1: "Reported COVID-19 deaths",
y2: "Total COVID-19 deaths",
strokeWidth: 0.5,
text: "Country"
}),
Plot.text(data, {
x: () => "Reported COVID-19 deaths",
y: "Reported COVID-19 deaths",
text: d => ["Italy", "Mexico"].includes(d.Country) ? "" : format(d["Reported COVID-19 deaths"]),
textAnchor: "end",
dx: -4
}),
Plot.text(data, {
x: () => "Total COVID-19 deaths",
y: "Total COVID-19 deaths",
text: d => ["Egypt", "Iran", "Brazil"].includes(d.Country) ? "" : format(d["Total COVID-19 deaths"]),
textAnchor: "start",
dx: +4
}),
Plot.text([0, 1e6], {
x: () => "Total COVID-19 deaths",
y: d=>d,
text: format,
textAnchor: "start",
fillOpacity: 0.5,
dx: +4
})
],
height: 600,
width: 350,
marginLeft: 0,
marginRight: 0
})