Public
Edited
Jun 14, 2023
Insert cell
Insert cell
Demographics_incidents.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
tmp2.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Demographics_incidents.csv
SELECT "Country" AS "country", "# of ncidents (Victims)" AS "count_victims", "# of incidents (Culprits)" AS "count_culprits" FROM "Demographics_incidents"
WHERE "# of incidents (Culprits)" > ${10}
Insert cell
culprits = {
const data = await FileAttachment("Demographics_incidents.csv").csv()
return data.map((d) => {
const country = d["Country"];
const count = d["# of incidents (Culprits)"] > 10 ? d["# of incidents (Culprits)"];
return {country, count};
});
}
Insert cell
Insert cell
Insert cell
tmp1.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
tmp1.csv
SELECT * FROM "tmp1" AS a JOIN "Demographics_incidents" AS b ON a."alpha2" = b."Country"
Insert cell
Plot.plot({
label: null,
x: {
axis: "top",
label: "← Victims · Number of Incidents (2022 - 2023) · Culprits →",
labelAnchor: "center",
tickFormat: Math.abs
},
// y: {
// axis: "left",
// filter: (d) => (d.count_culprits > 10),
// },
marks: [
// Plot.barX(demographics_incidents, {
// x: "count_culprits",
// y: "country",
// dy: +2,
// sort: { y: "-x" },
// filter: (d) => (d.count_culprits > 10),
// fill: "red",
// }),
Plot.barX(demographics_incidents, {
x: "count_victims",
y: "country",
// dy: -2,
filter: (d) => i < 10,
sort: { y: "-x" },
fill: "blue"
}),
Plot.text(demographics_incidents, {x: "count_victims", y: "country", text: "count_victims", dx: +10}),
// Plot.axisY({
// x: 0,
// filter: (d) => (d.count_culprits > 10),
// }),
// Plot.ruleX([0])
]
})
Insert cell
Plot.plot({
width: 1000,
height: 480,
insetLeft: 50,
insetRight: 50,
r: {range: [0, 30]},
marks: [
Plot.dot(demographics_incidents, Plot.dodgeY({x: "count_culprits", padding: 0}))
]
})
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