library(knitr)
opts_chunk$set(               cache=FALSE,
               echo=TRUE,
               message=FALSE,
               warning=FALSE) 
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(ggthemes)
library(tidyr)

World Map of Measles Vaccinations

World Development Indicators (WDI)

For this exercise we will work with data from the World Development Indicators (WDI). Vincent Arel-Bundock provides a nice package for R that makes it easy to import the data.

Select the data

Let’s get some data on measles vaccinations. SH.IMM.MEAS seems like a good fit. But feel free to use another variable you find interesting.

#install.packages("WDI")
library(WDI)

WDIsearch('measles')
##       indicator          
##  [1,] "HF.IMM.MEAS"      
##  [2,] "HF.IMM.MEAS.Q1"   
##  [3,] "HF.IMM.MEAS.Q2"   
##  [4,] "HF.IMM.MEAS.Q3"   
##  [5,] "HF.IMM.MEAS.Q4"   
##  [6,] "HF.IMM.MEAS.Q5"   
##  [7,] "SH.IMM.MEA2"      
##  [8,] "SH.IMM.MEAS"      
##  [9,] "SH.IMM.MEAS.Q1.ZS"
## [10,] "SH.IMM.MEAS.Q2.ZS"
## [11,] "SH.IMM.MEAS.Q3.ZS"
## [12,] "SH.IMM.MEAS.Q4.ZS"
## [13,] "SH.IMM.MEAS.Q5.ZS"
##       name                                                                                 
##  [1,] "Immunization, measles (% of children ages 15-23 months)"                            
##  [2,] "Immunization, measles (% of children ages 15-23 months): Q1 (lowest)"               
##  [3,] "Immunization, measles (% of children ages 15-23 months): Q2"                        
##  [4,] "Immunization, measles (% of children ages 15-23 months): Q3"                        
##  [5,] "Immunization, measles (% of children ages 15-23 months): Q4"                        
##  [6,] "Immunization, measles (% of children ages 15-23 months): Q5 (highest)"              
##  [7,] "Immunization, measles second dose (% of children by the nationally recommended age)"
##  [8,] "Immunization, measles (% of children ages 12-23 months)"                            
##  [9,] "Vaccinations (Measles) (% of children ages 12-23 months): Q1 (lowest)"              
## [10,] "Vaccinations (Measles) (% of children ages 12-23 months): Q2"                       
## [11,] "Vaccinations (Measles) (% of children ages 12-23 months): Q3"                       
## [12,] "Vaccinations (Measles) (% of children ages 12-23 months): Q4"                       
## [13,] "Vaccinations (Measles) (% of children ages 12-23 months): Q5 (highest)"
df <- WDI(indicator = "SH.IMM.MEAS", extra = TRUE)
df <- df %>% 
  filter(!is.na(SH.IMM.MEAS)) %>%
  filter(region != "Aggregates") %>%
  select(-c(capital, longitude, latitude)) 

world map of the share of infants vaccinated against measles

Using the map package and the measles data from the World Development indicators, we can make a world map of the share of infants vaccinated against measles.

library("rnaturalearth")
library("rnaturalearthdata")
world <- ne_countries(scale = "medium", returnclass = "sf")
df_2019 <- df %>%
  filter(year==2019) %>%
  select(country, SH.IMM.MEAS, iso3c) 
world_merged <- left_join(world, df_2019, by = c("iso_a3"="iso3c"))
ggplot(data = world_merged) +
  geom_sf(aes(fill=SH.IMM.MEAS), color= NA, alpha=0.8) +
  scale_fill_viridis_c(option = "plasma", na.value="gray90", breaks=seq(0,100,20), limits=c(20,100)) + 
  labs(title = "Fighting Measles with Vaccination",
       subtitle = "a world map of the share of infants vaccinated against measles",
       caption = "Source: World Development Indicators, World Bank 2019",
       fill = "% of infants \nvaccinated against measles") + 
  
  theme_map() + 
  
  theme(
    plot.subtitle=element_text(size=9, color="grey40", lineheight=.9, face="italic"), 
    plot.caption=element_text(size=7, color="grey40"),
    legend.title = element_text(size=7, color="grey40"))