chart = Plot.plot({
color: {
legend: true,
type: "categorical",
domain: ["female", "male"],
range: ["purple", "green"]
},
marks: [
Plot.linearRegressionY(
olympians.filter((d) => d.sport == sport_selected),
{ x: "height", y: "weight", stroke: "red" }
),
Plot.dot(
olympians
.filter((d) => d.sport == sport_selected)
.filter((d) => d.gold + d.silver + d.bronze == 0),
{
x: "height",
y: "weight",
fill: "sex",
opacity: 0.5,
tip: true,
title: (d) =>
[
"name: " + d.name,
d.nationality,
"altura:" + d.height + " m.",
"peso: " + d.weight + " kg",
"sin medallas 😢"
].join("\n")
}
),
Plot.circle(
olympians
.filter((d) => d.sport == sport_selected)
.filter((d) => d.gold + d.silver + d.bronze > 0),
{
x: "height",
y: "weight",
fill: "sex",
r: 5,
opacity: 1,
tip: true,
title: (d) =>
[
"name: " + d.name,
d.nationality,
"altura:" + d.height + " m.",
"peso: " + d.weight + " kg",
"🥇".repeat(d.gold) + "🥈".repeat(d.silver) + "🥉".repeat(d.bronze)
].join("\n")
}
)
]
})