Do you want to share your content on R-bloggers? Click here if you have a blog, or here If you don’t.
If this message is useful for you, I kindly request a minimum donation Buy a coffee for me. It will be used to continue my open source efforts. The complete explanation is here: A personal message from an Open Source employee.
You can send me questions for the blog using This form And subscribe to receive an e -mail when there is a new message.
Last week I had to use WBstats to get some time series, and I realized that it was removed from Cran. However, it is back now!
I contacted the subordiner, who explained that Cran asked for time -consuming changes in the structure and documentation of the package, and it was deleted about Cran’s policy on internet access.
Something similar happened with the Tradestatistics package that I made and that I have maintained for the past nine years. I have adjusted the Tradestatistics approach to meet Cran’s policy for WBSTats, which consisted of using mocking tests with pre-recorded API querys thanks to the VCR package, and now it is back to Cran. Other required changes where small changes in the documentation and package structure.
I will now maintain this package, so send me any problems or function requests that you have on the package Github -Repository.
You can install:
The latest release version of Cran with
install.packages("wbstats")or
Github’s newest development version with
remotes::install_github("pachadotdev/wbstats")library(wbstats)
# Population for every country from 1960 until present
d <- wb_data("SP.POP.TOTL")
head(d)# A tibble: 6 × 9 iso2c iso3c country date SP.POP.TOTL unit obs_status footnote last_updated1 AF AFG Afghanis… 2024 42647492 2025-07-01 2 AF AFG Afghanis… 2023 41454761 2025-07-01 3 AF AFG Afghanis… 2022 40578842 2025-07-01 4 AF AFG Afghanis… 2021 40000412 2025-07-01 5 AF AFG Afghanis… 2020 39068979 2025-07-01 6 AF AFG Afghanis… 2019 37856121 2025-07-01
The Gap Minder of his Rosling using wbstats
library(tidyverse)
library(wbstats)
my_indicators <- c(
life_exp = "SP.DYN.LE00.IN",
gdp_capita ="NY.GDP.PCAP.CD",
pop = "SP.POP.TOTL"
)
d <- wb_data(my_indicators, start_date = 2016)
d %>%
left_join(wb_countries(), "iso3c") %>%
ggplot() +
geom_point(
aes(
x = gdp_capita,
y = life_exp,
size = pop,
color = region
)
) +
scale_x_continuous(
labels = scales::dollar_format(),
breaks = scales::log_breaks(n = 10)
) +
coord_trans(x = 'log10') +
scale_size_continuous(
labels = scales::number_format(scale = 1/1e6, suffix = "m"),
breaks = seq(1e8,1e9, 2e8),
range = c(1,20)
) +
theme_minimal() +
labs(
title = "An Example of Hans Rosling's Gapminder using wbstats",
x = "GDP per Capita (log scale)",
y = "Life Expectancy at Birth",
size = "Population",
color = NULL,
caption = "Source: World Bank"
) 
Usage ggplot2 map wbstats facts
library(rnaturalearth)
library(tidyverse)
library(wbstats)
ind <- "SL.EMP.SELF.ZS"
indicator_info <- filter(wb_cachelist$indicators, indicator_id == ind)
ne_countries(returnclass = "sf") %>%
left_join(
wb_data(
c(self_employed = ind),
mrnev = 1
),
c("iso_a3" = "iso3c")
) %>%
filter(iso_a3 != "ATA") %>% # remove Antarctica
ggplot(aes(fill = self_employed)) +
geom_sf() +
scale_fill_viridis_c(labels = scales::percent_format(scale = 1)) +
theme(legend.position="bottom") +
labs(
title = indicator_info$indicator,
fill = NULL,
caption = paste("Source:", indicator_info$source_org)
)
Related
#WBstats #Cran #RBloggers

