Public
Edited
Feb 1, 2023
2 forks
3 stars
Insert cell
Insert cell
viewof radius = Inputs.range([0, 50], {value: 40, step: 0.1, label: "Max radius"})
Insert cell
test = Plot.plot({
grid: true,
width,
height: width/2,
marginLeft: 50,
marginRight: 50,
marginBottom: 50,
marks: [
Plot.dot(pData, {x: "Year", y: "Rank", r: d => scaleT(d['Trade value (US$)']), strokeWidth: 1, stroke: 'pink', fill:'pink' }), //
Plot.dot(pData, {x: "Year", y: "Rank", r: d => scaleC(d['Country size']), strokeWidth: 1, stroke: 'red' }),
Plot.text(pData, {x: "Year", y: "Rank", text: "Country", dy: 25}),
// Plot.dot(cars, {x: "economy (mpg)", y: "power (hp)"})
]
})
Insert cell
domainT = d3.extent(data.map(row=> row['Trade value (US$)']));
Insert cell
scaleT = d3.scaleLinear().domain(domainT).range([0.5, radius]);
Insert cell
domainC = d3.extent(data.map(row=> row['Country size']));
Insert cell
scaleC = d3.scaleLinear().domain(domainC).range([0.5, radius]);
Insert cell
pData = {
let countries = Array.from(new Set(data.map(row => row.Country)));
let years = Array.from(new Set(data.map(row => row.Year))).sort();
let newDf = [];
for (let y in years) {
let year = years[y];
let subdf = data.filter(row=> row['Year'] === year);
subdf = subdf.sort(function (a, b) { return b['Trade value (US$)'] - a['Trade value (US$)']});
subdf.map((row, i) => row['Rank'] = i+1);
subdf.map(row => newDf.push(row));
}
return newDf;
}
Insert cell
data = FileAttachment("global-sand.csv").csv({typed: true})
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