Published
Edited
Apr 1, 2021
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`### Attributes:
- Year: Temporal
- Country: Nominal
- Debt: Quantitative
- Income: Ordinal
- Continent: Nominal
- average debt(derived) : quantitative


### Marks:
- line where we can see the trend clearly.
- point where we use our mouse to pinpoint which data point we would like to see and its values
Insert cell
Insert cell
md `## How I got the data:
1. I retrieved IMF data on global central government debt and then deleted years before 1990. Then I had to add a column in front of all the values because of the nature of temporal data and how the IMF failed to provide me with data that was ready to be manipulated. I then put the new columns with the years and data into the same 2 rows for year and debt.
2. I copied the name column and pasted it to all the years so everything would look the same. (ex: afghanistan had 30 years of data and was year wasn't repeated by afghanistan was repeated for 30 times.
3. I did a vlookup on the continent list so I could select by continent in one of my graphs.
4. I did another vlookup on the income level so I could select by income.
`
Insert cell
data = FileAttachment("imf-dm-export-20210325@5.csv").csv()
Insert cell
// getting data that i need for only 2019
data_2019 = data
.map(d => ({
Country: d.Country,
year: Number(d.Year),
Debt: Number(d['Debt_%GDP']),
Income: d.Income
}))
.filter(d => (d.year == 2019))
Insert cell
// getting the G20 data from the 2019 data
G20 = data_2019.filter(d => d.Country == 'Argentina' ||
d.Country == 'Canada' ||
d.Country == 'United States' ||
d.Country == 'Australia' ||
d.Country == 'United Kingdom' ||
d.Country == 'Brazil' ||
d.Country == 'Canada' ||
d.Country == 'Germany' ||
d.Country == 'France' ||
d.Country == 'India' ||
d.Country == 'Indonesia' ||
d.Country == 'Italy' ||
d.Country == 'Japan' ||
d.Country == 'Mexico' ||
d.Country == 'Russia' ||
d.Country == 'Saudi Arabia' ||
d.Country == 'South Africa' ||
d.Country == 'South Korea' ||
d.Country == 'Turkey')
Insert cell
continent = uniqueValid(data, d => d.Continent)
Insert cell
income_level = uniqueValid(data, d => d.Income)
Insert cell
import {uniqueValid} from '@uwdata/data-utilities'
Insert cell
embed = require("vega-embed")
Insert cell
vegaDatasets = require("vega-datasets")
Insert cell
import {vl} from '@vega/vega-lite-api'
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