I'm a new beginner of R.I want to use WDI to download global GDP per capita (constant 2015 US$) , like this figure. But I don't know how to define "country" in wdi. I only get all country of GDP, but I can't get global data.
global_gdp <- WDI(indicator = "NY.GDP.PCAP.KD", start = 1990, end = 2019)
CodePudding user response:
Once you call the data from WDI, could you sum it within R and plot from there?
Rough example (haven't checked for accuracy):
# Import libraries.
library(WDI)
library(tidyverse)
# Call data from WDI package.
global_gdp <- WDI(
country = "all",
indicator = "NY.GDP.PCAP.KD",
start = 1990,
end = 2019,
)
# Add together the country data by year.
global_gdp2 <- global_gdp %>%
group_by(year) %>%
summarise((count = sum(NY.GDP.PCAP.KD, na.rm = TRUE))) %>%
rename(count = c(2))
# Plot the resulting data.
ggplot(data = global_gdp2, mapping = aes(x = year, y = count))
geom_line()
geom_point()
CodePudding user response:
guys, I find a solution from R studio community. for example:
global_gdp <- WDI(
country = "1W",
indicator = "NY.GDP.PCAP.KD",
start = 1990,
end = 2019,
)