12.6 Data
library(rnaturalearth)
library(sp)
<- ne_countries()
map names(map)[names(map) == "iso_a3"] <- "ISO3"
names(map)[names(map) == "name"] <- "NAME"
plot(map)
We obtain PM 2.5 concentration levels using the wbstats package. This package permits to retrieve global indicators published by the World Bank.
If we are interested in obtaining air pollution indicators, we can use the wbsearch() function setting pattern = “pollution”. This function searches all the indicators that match the specified pattern and returns a data frame with their IDs and names. We assign the search result to the object indicators that can be inspected by typing indicators.
library(wbstats)
<- wbsearch(pattern = "pollution") indicators
## Warning: `wbsearch()` was deprecated in wbstats 1.0.0.
## ℹ Please use `wb_search()` instead.
- We decide to plot the indicator PM2.5 air pollution, mean annual exposure (micrograms per cubic meter) which has code EN.ATM.PM25.MC.M3 in 2016. To download these data, we use the wb() function providing the indicator code and the start and end dates.
<- wb(
d indicator = "EN.ATM.PM25.MC.M3",
startdate = 2016, enddate = 2016
)
## Warning: `wb()` was deprecated in wbstats 1.0.0.
## ℹ Please use `wb_data()` instead.
head(d)
## iso3c date value indicatorID
## 1 AFE 2016 35.49775 EN.ATM.PM25.MC.M3
## 2 AFW 2016 57.33405 EN.ATM.PM25.MC.M3
## 3 ARB 2016 59.15009 EN.ATM.PM25.MC.M3
## 4 CSS 2016 19.25183 EN.ATM.PM25.MC.M3
## 5 CEB 2016 17.64109 EN.ATM.PM25.MC.M3
## 6 EAR 2016 59.97910 EN.ATM.PM25.MC.M3
## indicator iso2c
## 1 PM2.5 air pollution, mean annual exposure (micrograms per cubic meter) ZH
## 2 PM2.5 air pollution, mean annual exposure (micrograms per cubic meter) ZI
## 3 PM2.5 air pollution, mean annual exposure (micrograms per cubic meter) 1A
## 4 PM2.5 air pollution, mean annual exposure (micrograms per cubic meter) S3
## 5 PM2.5 air pollution, mean annual exposure (micrograms per cubic meter) B8
## 6 PM2.5 air pollution, mean annual exposure (micrograms per cubic meter) V2
## country
## 1 Africa Eastern and Southern
## 2 Africa Western and Central
## 3 Arab World
## 4 Caribbean small states
## 5 Central Europe and the Baltics
## 6 Early-demographic dividend
- to calculate the positions of the ISO3 code in the map (map\(ISO3) in the data (d\)iso3c), and assign d\(value to map\)PM2.5 in that order.
$PM2.5 <- d[match(map$ISO3, d$iso3c), "value"] map
- We can see the first rows of map by typing head(map).