Public
Edited
Oct 10, 2023
2 forks
1 star
Insert cell
Insert cell
Insert cell
Insert cell
addTooltips(Plot.plot({
marginRight: 100,
insetBottom: 0,
insetLeft:0,
insetTop: 30,
color: {legend: false, scheme: "ylorrd", width: 400},
marks: [
Plot.barX([70], {fill: "gray", fillOpacity: .5}),
Plot.barX([-10], {fill: "skyblue", fillOpacity: 1}),
Plot.barY([-45], {fill: "orange", fillOpacity: .5}),
Plot.text(['🌋'], {x:0,y:-18, fontSize: 300,}),
Plot.text(['Duration of volcano eruptions since 1950'], {x:39,y:-25, fontSize: 45, fill: "maroon", lineWidth: 20, opacity: 0.8}),
Plot.text(['The Aira volcano in Japan\nstarted erupting in 1955 and\ncontinued erupting until 2016.'], {x:68,y:70, fontSize: 16, fill: "maroon", lineWidth: 20, opacity: 0.8, textAnchor: "end", filter: d=>yearsvolcano>60}),
Plot.text(['years'], {x:69,y:-4, fontSize: 25, fill: "maroon", textAnchor: "end", filter: d=>yearsvolcano>60}),
Plot.text(['Design: Deepsha Menghani | Twitter: Bigdatadipper | Data: Tidy Tuesday'], {x:69,y:-43, fontSize: 15, fill: "gray", textAnchor: "end", fontStyle: "oblique"}),
Plot.arrow(volcanoes_1950, {x1: 0, y1: 0, x2: "years", y2: "years", stroke: "years", bend: true, filter: d=>d.years!=0 & d.years<= yearsvolcano, title: d=>d.volcanoes}),
Plot.link(volcanoes_1950, {x1: "years", y1: "years", x2: "years", y2: 0, stroke: "years",
filter: d=>d.years!=0 & d.years<= yearsvolcano,
title: d=>d.volcanoes}),
Plot.text(volcanoes_1950, {x:"years",y:-4, text: "years", fill: "years", fontSize: d=>10+d.years*.3, filter: (d=>d.years>28 & d.years!=42 & d.years<= yearsvolcano)}),
Plot.text(volcanoes_1950, {x:"years",y:-4, text: "years", fill: "years", dx: -13, fontSize: d=>10+d.years*.3, filter: (d=>d.years===42& d.years<= yearsvolcano)}),
Plot.text(volcanoes_1950, {x:"years",y:-4, text: "years", fill: "red", fontSize: d=>10, dx:-4, filter: d=>d.years<=28& d.years<= yearsvolcano}),
Plot.axisY({ tickSize: 0, fontSize: 0 }),
Plot.axisX({ tickSize: 0, fontSize: 0 }),
], width: 1300, height: 700
}), {stroke: "maroon", "stroke-width": 6}
)
Insert cell
Insert cell
Plot.plot({
style: "overflow: visible;",
marginBottom: 50,
marginLeft: 75,
insetBottom: 10,
insetLeft: 10,
marks: [Plot.barY([23], {fill: "black", fillOpacity: 1}),
Plot.ruleX([6.5], {stroke: "gray", opacity: 0}),
Plot.ruleX([10], {stroke: "gray", opacity: 0}),
Plot.ruleY([0], {stroke: "gray", opacity: 0.2}),
Plot.text([`Spurious Correlations`], {x:6.5, y:21.5, frameAnchor: "middle", fontSize: 70, lineWidth: 25, textAnchor: "start", lineHeight: 1.2, clip: false, fill: "white", opacity: 1, fontStyle: "oblique"}),
Plot.text([`Drink less beer, Get attacked less by bears!!`], {x:6.5, y:18.9, frameAnchor: "middle", fontSize: 40, lineWidth: 25, textAnchor: "start", lineHeight: 1.2, clip: false, fill: "white", opacity: 1}),
Plot.text([`Months with higher % beer production saw a higher % of bear attacks.`], {x:7.7, y:10, frameAnchor: "middle", fontSize: 20, lineWidth: 10, textAnchor: "start", lineHeight: 1.2, clip: false, fill: "gray", opacity: 1, fontStyle: "oblique"}),
Plot.dot(beer_bear_correlation, {x: "perc_prod", y: "perc_attacks", r: 10, stroke: "#d2b48c", fill: "#d2b48c", title: d=>d.monthabb, opacity: 1}),
Plot.dot(beer_bear_correlation, {x: "perc_prod", y: d=>d.perc_attacks-0.1, r: 4, stroke: "lightblue", fill: "white", title: d=>d.monthabb}),
Plot.text(beer_bear_correlation, {x: d=>d.perc_prod+0.1, y: d=>d.perc_attacks+0.6, r: 3, fill: "gray", text: d=>d.monthabb}),
Plot.linearRegressionY(beer_bear_correlation, {x: "perc_prod", y: "perc_attacks", ci: 0.1, stroke: "white"}),
Plot.image(beer_bear_correlation, {x: 9.49, y: 4.9, width: 260,
src: "https://th.bing.com/th/id/OIP.YcBnzliiACwk4-5FX6qI5QHaHa?w=159&h=180&c=7&r=0&o=5&dpr=1.3&pid=1.7"
}),
Plot.image(beer_bear_correlation, {x: 9.6, y: 4, width: 100,
src: "https://th.bing.com/th/id/OIP._vZBqe6o4WNetvdqVfYAnwHaHP?w=171&h=180&c=7&r=0&o=5&dpr=1.3&pid=1.7"
}),
Plot.axisY({ tickSize: 0, fontSize: 18, label: "Percentage of Bear attacks", anchor: "left", labelAnchor: "center", ticks: 4}),
Plot.axisX({ tickSize: 0, fontSize: 18, label: "Percentage of Beer production", anchor: "bottom", labelAnchor: "center", ticks: 4}),
],
height: 700,
width: 900
})
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
insetTop: 10,
insetBottom: 10,
marks: [Plot.image(avocadoprices.slice(0,1), {x: "Date", y: 1.4, src: "url", title: "Date", width: 700, dx: 500, opacity: .1}),
Plot.barY([3], {fill: "green", fillOpacity: 0.04}),
Plot.barY([2.52], {fill: "pink", fillOpacity: 0.1}),
Plot.lineX(avocadoprices, Plot.windowY({x: "Date", y: "AveragePrice", k: k, stroke: "type", strokeWidth: 2,
filter: d=>d.region === regionselected,
//filter: d=>d.Date >= dateinput,
title: "AveragePrice"})),
Plot.text(['Maximum average price across regions over time'], { y: 2.46, fontSize: 15, dx: -300, fill: "orange"}),
Plot.text(['Avocado price over time'], { y: 2.7, fontSize: 60, dx: +470, fill: "gray", textAnchor: "end", opacity: 0.7}),
Plot.text(['-Organic'], { y: 2.1, fontSize: 20, dx: -460, fill: "forestgreen", textAnchor: "start"}),
Plot.text(['-Conventional'], { y: 0.6, fontSize: 20, dx: -460, fill: "maroon", textAnchor: "start"}),
Plot.ruleY([0]),
Plot.ruleY([2.52], {stroke: "orange"}),
Plot.axisY({ tickSize: 0, fontSize: 14 }),
Plot.axisX({ tickSize: 0, fontSize: 15 }),
Plot.text(['Design: Deepsha Menghani | Twitter: Bigdatadipper | Data: Tidy Tuesday'], {y:.05, dx: 460, fontSize: 12, fill: "gray", textAnchor: "end", fontStyle: "oblique"}),
],
color: {
type: "categorical", range: ["forestgreen", "maroon"], domain: ["organic", "conventional"], legend: false,
style: {
fontSize: "20px",
}
},
width: 1000, height: 500
})
Insert cell
Insert cell
addTooltips(Plot.plot({
marginTop: 25,
insetBottom: 10,
projection: "equirectangular",
marks: [Plot.sphere({fill: "black"}),
Plot.geo(land, {fill: "black", opacity: .8, stroke: "gray"}),
Plot.dot(renewable, {x: "longitude", y: "latitude", r: "renewable_perc", fill: "renewable_perc", opacity: .6, title: d=>d.name+" \n"+d.renewable_perc_char, filter: d=> d.Year === 2020}),
Plot.dot(renewable, {x: "longitude", y: "latitude", r: "renewable_perc", fill: "renewable_perc", opacity: .5, title: d=>d.name+" \n"+d.renewable_perc_char, filter: d=>d.renewable_perc>50 & d.Year === 2020}),
Plot.density(renewable, {x: "longitude", y: "latitude", bandwidth: 3, thresholds: 20, stroke: "white", fill: "renewable_perc", fillOpacity: 0.25, mixBlendMode: "multiply", weight: "renewable_perc", title: d=>d.name+" \n"+d.renewable_perc_char}),
Plot.text(['% of primary energy that comes from renewables (2020)'],{x:30, y: 88, dy: -60, fontSize: 25, fill: "black", opacity: 1, lineHeight: 1.2}),
Plot.text(['Data source: Ourworldindata.org, Design: Deepsha Menghani'],{x:40, y: -85, fontSize: 10, fill: "gray", opacity: 1, lineHeight: 1.2 }),
],
width: 1000,
r: { range: [5, 20]},
color: {type: "sequential", label: "", legend: true, scheme: "ylgnbu", style: {fontSize: 20}}
}), {fill: d => d.n, stroke: "gray", "stroke-width": 1}
)
Insert cell
Plot.plot({
inset: 40,
projection: "Equal-Earth",
width,
marks: [
Plot.geo(land, {fill: "gray", opacity: .3, stroke: "black"}),
Plot.geo(land, {opacity: .9, stroke: "black"}),
Plot.graticule(),
Plot.dot(renewable, {x: "longitude", y: "latitude", r: "renewable_perc", fill: "renewable_perc", opacity: 1, title: d=>d.name+" \n"+d.renewable_perc_char, filter: d=> d.Year === 2020}),
Plot.dot(renewable, {x: "longitude", y: "latitude", r: "renewable_perc", fill: "renewable_perc", opacity: 1, title: d=>d.name+" \n"+d.renewable_perc_char, filter: d=>d.renewable_perc>50 & d.Year === 2020}),
Plot.text(['Data source: Our World In Data, Design: Deepsha Menghani'],{x:70, y: -80, fontSize: 10, fill: "black", opacity: 1, lineHeight: 1.2 }),
//Plot.density(renewable, {x: "longitude", y: "latitude", bandwidth: 3, thresholds: 20, stroke: "renewable_perc", fill: "renewable_perc", fillOpacity: 0.25, mixBlendMode: "multiply", weight: "renewable_perc", title: d=>d.name+" \n"+d.renewable_perc_char}),
Plot.sphere()
],
r: { range: [5, 20]},
color: {legend:true, scheme: "ylgnbu", label: "What percentage of our primary energy comes from renewables? (2020)", style: {fontSize: 30}}
})
Insert cell
Insert cell
addTooltips(Plot.plot({
marginLeft: 100,
insetLeft: 200,
marginTop: 150,
marginBottom: 10,
marginRight: 200,
marks: [Plot.image(amtrak,{y: 0, x:0, dy:-100, dx: -180, width: 300, opacity: .003, src: "https://blog.amtrak.com/wp-content/uploads/2013/10/amtrak-011-e1437095759125.jpg"}),
Plot.text(['🚄'],{y: 2, x:0, textAnchor: "start", fontSize: 800, dy:0, dx: -550, }),
Plot.text(['⬜️'],{y: 2, x:0, textAnchor: "start", fontSize: 690, dy:-50, dx: -127, opacity: 1 }),
Plot.text(['Number of Amtrak stations in the United States'],{y: 0, x:0, fontSize: 30, dy:-150, dx: 350, lineWidth: 25, lineHeight: 1.3, fontStyle: "normal", fontFamily: "Menlo", fontWeight: "bold", opacity: 0.7}),
Plot.text(['Design: Deepsha Menghani Twitter: BigDataDipper Source: DataWorld'],{y: 3, x:0, fontSize: 12, dy:127, dx: 550, lineWidth: 15, lineHeight: 1.3, fontStyle: "oblique", fontFamily: "Menlo", opacity: 0.5}),
Plot.cell(
amtrak,
Plot.stackX({
y: (_, i) => i % 5,
fill: "n",
title: d=>d.state + "\n" + d.n + "\n" ,
opacity: 0.3,
dy: -50
})
),
Plot.text(
amtrak,
Plot.stackX({
y: (_, i) => i % 5,
text: "emoji5",
fontSize: d=>20 + d.n*.2,
title: d=>d.state + "\n" + d.n + "\n",
dy: -50
})
),
Plot.text(
amtrak,
Plot.stackX({
y: (_, i) => i % 5,
text: "stateabb",
fontSize: 20,
dy: -10,
title: d=>d.state + "\n" + d.n + "\n"
})
),
Plot.axisX({ tickSize: 0, fontSize: 0 }),
],
x: { axis: null },
y: { axis: null },
height: 700,
width: 1200,
}), {fill: d => d.n, stroke: "black", "stroke-width": 4}
)
Insert cell
Insert cell
addTooltips(Plot.plot({
marginTop: 25,
insetBottom: 10,
projection: "Equal-Earth",
marks: [Plot.sphere({fill: "white"}),
Plot.geo(countries, {fill: "gray", opacity: .3, stroke: "white"}),
Plot.geo(countries, {fill: (d)=> labor_2020.get(d.properties.name), opacity: 1, stroke: "white",
title: (d)=> d.properties.name + "\n" + Math.round(labor_2020.get(d.properties.name))+"%"
}),
Plot.text(['Ratio of female to male labor force participation rate (%)'],{x:80, y: 100, dy: -60, fontSize: 30, fill: "black", opacity: 1, lineHeight: 1.2}),
Plot.text(['Data source: data.worldbank.org, Design: Deepsha Menghani'],{x:70, y: -77, fontSize: 10, fill: "black", opacity: 1, lineHeight: 1.2 }),
],
width: 1000,
r: { range: [5, 20]},
color: {type: "sequential", legend: true, scheme: "blues", style: {fontSize: 20}}
}), {fill: d => d.n, stroke: "gray", "stroke-width": 1}
)
Insert cell
femaletomalelabor.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
labor = (await FileAttachment("femaletomalelabor.csv").csv()).map(d => ({name: rename.get(d.country) || d.country, Year2022: +d.Year2022}))
Insert cell
rename = new Map([
["Antigua and Barbuda", "Antigua and Barb."],
["Bolivia (Plurinational State of)", "Bolivia"],
["Bosnia and Herzegovina", "Bosnia and Herz."],
["Brunei Darussalam", "Brunei"],
["Central African Republic", "Central African Rep."],
["Cook Islands", "Cook Is."],
["Democratic People's Republic of Korea", "North Korea"],
["Democratic Republic of the Congo", "Dem. Rep. Congo"],
["Dominican Republic", "Dominican Rep."],
["Equatorial Guinea", "Eq. Guinea"],
["Iran (Islamic Republic of)", "Iran"],
["Lao People's Democratic Republic", "Laos"],
["Marshall Islands", "Marshall Is."],
["Micronesia (Federated States of)", "Micronesia"],
["Republic of Korea", "South Korea"],
["Republic of Moldova", "Moldova"],
["Russian Federation", "Russia"],
["Saint Kitts and Nevis", "St. Kitts and Nevis"],
["Saint Vincent and the Grenadines", "St. Vin. and Gren."],
["Sao Tome and Principe", "São Tomé and Principe"],
["Solomon Islands", "Solomon Is."],
["South Sudan", "S. Sudan"],
["Swaziland", "eSwatini"],
["Syrian Arab Republic", "Syria"],
["The former Yugoslav Republic of Macedonia", "Macedonia"],
["United States", "United States of America"],
// ["Tuvalu", ?],
["United Republic of Tanzania", "Tanzania"],
["Venezuela (Bolivarian Republic of)", "Venezuela"],
["Viet Nam", "Vietnam"]
])
Insert cell
world = FileAttachment("countries-50m.json").json()
Insert cell
countries = topojson.feature(world, world.objects.countries)
Insert cell
labor_2020 = new Map(labor.map(({name, Year2022}) => [name, Year2022]))
Insert cell
amtrack.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
import {addTooltips} from "@mkfreeman/plot-tooltip"
Insert cell
land50m = FileAttachment("land-50m@1.json").json()
Insert cell
land = topojson.feature(land50m, land50m.objects.land)
Insert cell
volcanoes_1950@1.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

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

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

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

Insert cell
avocado
with ordereddata as
(
select Date, type, region, mean(AveragePrice) as AveragePrice
from avocado
where region in ('West', 'SouthCentral', 'Midsouth','Northeast','Southeast')
group by Date, type, region
order by Date, type
), uniondata as(
select Date, AveragePrice, type, Region,
AveragePrice - LAG(AveragePrice, 1) OVER (PARTITION BY type, region ORDER BY Date) as pricediff
from ordereddata
)
select *, case when pricediff < 0 then 'negative'
when pricediff > 0 then 'positive' else 'neutral' end AS sign ,
'https://th.bing.com/th/id/OIP.v_AeJp-94Is2i10Y2scNWwHaEz?w=264&h=180&c=7&r=0&o=5&dpr=1.3&pid=1.7' as url
from uniondata


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

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