Public
Edited
Jan 27, 2023
Insert cell
Insert cell
urbanDomain = d3.extent(iataData.map(row => row['urban_sqkm']));
Insert cell
freeDomain = d3.extent(iataData.map(row => row['free_sqkm']));
Insert cell
changeColor(dotPlot, 12, 'black')
Insert cell
dotPlot = Plot.plot({
width: 270,
height: 900,
insetRight: 100,
labelOffset: 100,
// grid: true,
x: {
domain: freeDomain
},
// fx: {
// labelOffset: -200,
// },
marks: [
Plot.frame({stroke: "#d8d8d8", strokeWidth: 1}),
//Plot.dotX(cars, Plot.dodgeX({x: "urban_10", title: "name", fill: "sub_continent", fy: "sub_continent"})),
// Plot.rectY(iataData, Plot.binX({y: "count"}, {x: "free_sqkm", fill: "sub_continent", fy: "sub_continent", })),
// Plot.areaY(iataData, Plot.binX({y: "count"}, {x: "urban_10", fill: d => colorScale(d['sub_continent']), curve: 'basis', fy: "sub_continent", opacity: 0.4})),
// Plot.ruleY([0]),
// Plot.dot(iataData, Plot.dodgeY({x: jitter(iataData, seed), padding:0.1, fill: d => colorScale(d['sub_continent']), fy: 'sub_continent', anchor: 'middle', r:1})),
Plot.dot(iataData, Plot.dodgeY({x: "free_sqkm", padding:0.01, fill: d => colorScale(d['sub_continent']), fy: 'sub_continent', anchor: 'middle', r:0.7})),
],

})

Insert cell
import {jitter} from "@spren9er/raincloud-plots-with-observable-plot"
Insert cell
viewof seed = Inputs.range([1, 100], { step: 1, label: 'Raw Data Seed', value: 1 })
Insert cell
seedrandom = require('seedrandom')
Insert cell
Insert cell
// changeColor(barplot, 10, 'black')
Insert cell
thresholds=10
Insert cell
combined= Plot.plot({
// inset: 20,
width: width/4,
marks:[
Plot.frame({stroke: "#d8d8d8", strokeWidth: 1}),
// Plot.rectY(iataData, Plot.binX({y: "count"}, {x: "urban_sqkm", thresholds: thresholds,fill: "sub_continent", fy: 'sub_continent'})),
Plot.dot(data, Plot.dodgeY({x: "urban_sqkm", padding:0.4, fill: 'green', fy: 'sub_continent', anchor, r:1.5})),
// Plot.areaY(
// data,
// Plot.binX(
// {
// y: 'count'
// },
// {
// x: 'free_sqkm',
// fill: d => colorScale(d['sub_continent']),
// thresholds: thresholds,
// curve: 'basis',
// opacity: 0.4,
// fy: 'sub_continent',
// }
// )
// )
]
})
Insert cell
viewof anchor = Inputs.radio(["top", "middle", "bottom"], {label: "Anchor", value: "bottom"})
Insert cell
Insert cell
changeColor(combined, "black", 12)
Insert cell
function changeColor (chart, color, fontsize) {
d3
.select(chart)
.select("[aria-label=x-axis]")
.selectAll("text")
.each(function (d) {
// d is the tick's value (in this case, a number)
d3.select(this)
.attr("fill", color)
.attr("font-size", fontsize)
.attr("font-family", "IBM Plex Sans");
})

d3
.select(chart)
.select("[aria-label=y-axis]")
.selectAll("text")
.each(function (d) {
// d is the tick's value (in this case, a number)
d3.select(this)
.attr("fill", color)
.attr("font-size", fontsize)
.attr("font-family", "IBM Plex Sans");
})

d3
.select(chart)
.select("[aria-label=x-axis]")
.selectAll("line")
.each(function (d) {
// d is the tick's value (in this case, a number)
d3.select(this)
.attr("stroke", color)
})

d3
.select(chart)
.select("[aria-label=y-axis]")
.selectAll("line")
.each(function (d) {
// d is the tick's value (in this case, a number)
d3.select(this)
.attr("stroke", color)
})

d3.select(chart)
.selectAll("text")
.each(function(d) {
d3.select(this)
.attr("font-family", "IBM Plex Sans");
})


}
Insert cell
// Plot.plot({
// width:width/1.5,
// height: 1000,
// marks: [
// Plot.dot(data, Plot.dodgeY({x: "urban_10", fill: "sub_continent", fy: "sub_continent", anchor}))
// ]
// })
Insert cell
// Plot.plot({
// insetRight: 10,
// marginLeft: 100,
// height: 400,
// width,
// marks: [
// Plot.dot(
// data,
// Plot.dodgeX({
// y: "sub_continent",
// r: "urban_10",
// title: d => `${d.NAME}\n${(d.rMVOP / 1e3).toFixed(1)}B`,
// fill: "currentColor"
// })
// ),
// // Plot.text(
// // data,
// // Plot.dodgeX({
// // filter: (d) => d.rMVOP > 5e3,
// // y: "sub_continent",
// // r: "urban_10",
// // text: d => (d.rMVOP / 1e3).toFixed(),
// // fill: "white",
// // fontWeight: "bold"
// // })
// // )
// ]
// })
Insert cell
// Plot.plot({
// height: 180,
// marks: [
// Plot.dot(iataGroupedByRegions, Plot.dodgeY({x: "sub_continent",}))
// ]
// })
Insert cell
data =
{
let df = iataGroupedByRegions.filter(row => sub_continents.includes(row['sub_continent']))
// for (let i in df){
// df[i]['combined_10'] = iataGroupedByRegions[i]['empty_10'] + iataGroupedByRegions[i]['arid_10'];
// df[i]['combined_sqkm'] = iataGroupedByRegions[i]['combined_10'] * 13 / 1e6;
// df[i]['urban_sqkm'] = iataGroupedByRegions[i]['urban_10'] * 13 / 1e6;
// }
return df;
}
Insert cell
range = ["#ff595e", "#ff924c", "#ffca3a", "#8ac926", "#1982c4", "#6a4c93",
"#E04E53", "#DD7275", "#FA8D91", "#FFA6A8",
"#FF924C", "#E0884F", "#FBA771", "#FFCBA9",
"#73AA1C", "#70A51E" ,"#9FC95C" ,"#B9E375", "#B9E375",
"#FFE9AF", "#FFCA3A", "#1982C4",
"#9D88BA",
"#BCE784", "#5DD39E", "#348AA7", "#513B56",
]
Insert cell
domain = ["EU", "AS", "SA", "AF", "NA", "OC",
"Central and East Europe", "North Europe", "South Europe", "West Europe",
"East Asia", "Southeast Asia", "South Asia", "West Asia",
"Central Africa", "East Africa", "North Africa", "South Africa", "West Africa",
"South America", 'Central America', "North America",
"Australia and New Zealand",
"Trains", "Electric aircraft", "Hydrogen aircraft", "Petroleum", ]
Insert cell
new Set(iataData.map(row => row['sub_continent']));
Insert cell
colorScale = d3.scaleOrdinal().domain(domain).range(range)
Insert cell
Insert cell
iataData = FileAttachment("iata-sqkm@3.csv").csv({typed: true})
Insert cell
import {sub_continents} from "4b75e48934b7ce6a"
Insert cell
import {iataGroupedByRegions} from "b7b073d13cec22e7"
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