Public
Edited
Apr 22, 2024
1 fork
Insert cell
Insert cell
bertin.draw({
params: { projection: d3.geoMercator(),
margin: 20,
height: 550,
extent: [[22.0856083513, 40.0807890155],[44.3614785833, 52.3350745713]]},
layers: [
{
type: "header",
text: `War impact on grain production in Ukraine`,
fontSize: 30
},
{
type: "mushroom",
geojson: grain_geo,
top_values: "vol_2022",
bottom_values: "vol_2021",
k: 30,
bottom_tooltip: {
fields: ["$region",
d => "Volume: " + Math.round(d.properties.vol_2021 * 10) / 10 + " mmt"],
col: "#4fabd6"
},
top_tooltip: { fields: ["$region",
d => "Volume: " + Math.round(d.properties.vol_2022 * 10) / 10 + " mmt"],
col: "#d64f4f" },
leg_x: 100,
leg_y: 350,
leg_title: "Grain production, mm tons",
leg_top_fill: "none",
leg_bottom_fill: "none",
leg_top_txt: "2022",
leg_bottom_txt: "2021",
leg_fontSize: 16,
leg_round: 1
},
{
type: "layer",
geojson: ukraine,
fill: "#e4d96f",
fillOpacity: 0.5,
stroke: "white"
}
]
})
Insert cell
grain_geo = bertin.merge(geo.centroid(ukraine), "name", grain_agg, "region_alt")
Insert cell
grain_agg = aq.from(grain)
.groupby("year", "region")
.rollup({volume: d => op.sum(d.production / 1000)})
.groupby("region")
.pivot("year", "volume")
.rename({2021: "vol_2021", 2022: "vol_2022"})
.objects()
.map(d => ({...d, region_alt: name_mapping[d.region]})) // change region name spelling
Insert cell
// Mapping between different name spellings in .csv and .geojson files
name_mapping = {
const reg_old = ukraine.features.map(d => d.properties.name).sort()
const reg_new = ["Cherkasy", "Chernihiv", "Chernivtsi", "Crimea", "Dnipropetrovsk", "Donetsk", "Ivano-Frankivsk", "Kharkiv", "Kherson", "Khmelnytskiy", "Kyiv", "Kirovohrad", "Lviv", "Luhansk", "Mykolayiv", "Odesa", "Poltava", "Rivne", "Sumy", "Ternopil", "Zakarpattya", "Vinnytsya", "Volyn", "Zaporizhzhya", "Zhytomyr"]
return _.zipObject(reg_new, reg_old) // merge two arrays into key-value pairs
}
Insert cell
ukraine
Insert cell
grain = FileAttachment("UKR grain 2021-2022@3.csv").csv({typed: true})
Insert cell
Insert cell
Insert cell
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