Andrea Amantini / Oct 11 2021 / Published
🐧 Palmer Penguins
Massage data in python - visualize in ObservableJS
https://observablehq.com/@observablehq/plot-exploration-penguins
[credits/R] https://allisonhorst.github.io/palmerpenguins
Run all python cells, then change and run the body-mass quantile cell below, to have the plot update.
from palmerpenguins import load_penguins
penguins = load_penguins()
penguins_clean = penguins \
.dropna() \
.drop(columns=['island', 'year'])
penguins_clean
1.5s
bmqt = penguins_clean["body_mass_g"].quantile(0.95)
df = penguins_clean[penguins_clean["body_mass_g"] < bmqt]
df.to_csv('/results/penguins.csv', index=False)
body-mass quantile
0.1s
data = FileAttachment("penguins.csv").csv({typed: true})
Plot.dot(data, {x: "flipper_length_mm",
y: "body_mass_g",
fill: "species",
title: "species"}).plot({ grid: true })
Plot.plot({
facet: {
data,
y: "species",
marginLeft: 80
},
marks: [
Plot.frame(),
Plot.tickX(data, Plot.groupZ({x: "median"}, {
x: "body_mass_g",
filter: d => d.sex === "female",
stroke: "species",
strokeWidth: 3
})),
Plot.tickX(data, Plot.selectMinX({
x: "body_mass_g",
filter: d => d.sex === "male",
stroke: "grey",
strokeWidth: 3
})),
Plot.tickX(data, Plot.selectMaxX({
x: "body_mass_g",
filter: d => d.sex === "male",
stroke: "grey",
strokeWidth: 3
})),
Plot.dot(data, {
x: "body_mass_g",
filter: d => d.sex === "male",
fill: "grey",
r: 2
}),
Plot.dot(data, {
x: "body_mass_g",
filter: d => d.sex === "female",
fill: "species"
})
]
})
Plot.rectY(data,
Plot.stackY(Plot.binX({y: "count"},
{x: "body_mass_g",
fill: "species",
thresholds: 20})))
.plot({facet: {
data,
x: "sex"
},
marks: [
Plot.frame(),
]
})
Appendix
pip install palmerpenguins
3.5s