Public
Edited
Mar 12
1 fork
Insert cell
Insert cell
Insert cell
happiness
X
social_support
Y
freedom_to_make_life_choices
Color
Size
Facet X
Facet Y
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
marks: [
Plot.dot(happiness, {
x: "social_support",
y: "freedom_to_make_life_choices",
tip: true
})
]
})
Insert cell
Plot.plot({
marks: [
Plot.barY(alphabet, {x: "letter", y: "frequency", sort: {x: "y", reverse: true}}),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
beeswarm = Plot.plot({
height: 600,
width: 1000,
x: { tickSize: 0, label: factor },
grid: true,
marks: [
// Main beeswarm plot
Plot.dotX(
happiness,
Plot.dodgeY({
x: factor,
title: (d) => `${d.country_name}: ${d[factor]}`,
fill: (d) => (d.country_name === country ? "#006e90" : "#d3d3d3"),
anchor: "middle",
opacity: 1,
padding: 2,
r: 8
})
),

// Dotted line at median value
Plot.ruleX([median], {
stroke: "black",
strokeDasharray: "4,4", // Dotted line
strokeWidth: 1,
opacity: 0.7
})
]
})
Insert cell
import { Plot } from "@mkfreeman/plot-tooltip"
Insert cell
median = d3.median(happiness, (d) => d[factor])
Insert cell
features = [
"ladder_score",
"log_gdp_per_capita",
"social_support",
"healthy_life_expectancy",
"freedom_to_make_life_choices",
"generosity",
"perceptions_of_corruption"
]
Insert cell
happiness.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
happiness
SELECT country_name, 'ladder_score' AS Feature, Ladder_score AS Value
FROM happiness
UNION ALL
SELECT country_name, 'upperwhisker', upperwhisker
FROM happiness
UNION ALL
SELECT country_name, 'lowerwhisker', lowerwhisker
FROM happiness
UNION ALL
SELECT country_name, 'log_gdp_per_capita', Log_GDP_per_capita
FROM happiness
UNION ALL
SELECT country_name, 'social_support', Social_support
FROM happiness
UNION ALL
SELECT country_name, 'healthy_life_expectancy', Healthy_life_expectancy
FROM happiness
UNION ALL
SELECT country_name, 'freedom_to_make_life_choices', Freedom_to_make_life_choices
FROM happiness
UNION ALL
SELECT country_name, 'generosity', Generosity
FROM happiness
UNION ALL
SELECT country_name, 'perceptions_of_corruption', Perceptions_of_corruption
FROM happiness
UNION ALL
SELECT country_name, 'dystopia_residual', Dystopia_residual
FROM happiness;

Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more