Introduction

The following document contains a series of visualizations made by utilizing the COVID-19 data of countries.

Environment Setup

First, we will load several visualization packages and a data set package into our environment to utilize in the process of data visualization.

# install.packages("sf")
library(sf)
# install.packages("rnaturalearth")
library(rnaturalearth)
# install.packages("rnaturalearthdata")
library(rnaturalearthdata)
# install.packages("gganimate")
library(gganimate)
# install.packages("gifski")
library(gifski)
# install.packages("transformr")
library(transformr)
# install.packages("ggalt")
library(ggalt)
# install.packages("dplyr")
library(dplyr)
# install.packages("tidyr")
library(tidyr)

We will also load in our COVID-19, contained in the data frame country_daily_data.RDS.

covid <- readRDS("country_daily_data.RDS")

To obtain the data for the shapes of each country, the package sf will be used. Along with geographical information, this package also contains other possibly useful data. We will save this data in the data frame world.

world <- ne_countries(scale = "medium", returnclass = "sf")

We will now merge this data with our Covid data, keeping the geometry property contained as it will be crucial for the next steps.

geo <- world %>%
  dplyr::rename(iso3c = iso_a3) %>%
  select(iso3c, geometry)

covid_map <- merge(geo, covid,             
                  by = "iso3c",
                  all.x = T)

Visualization

Our first visualization will be that of the percentage of fully vaccinated people in each country.

maxFeb <- covid %>%
  #select(country, date, fully_vaccinated_pct) %>%
  filter(date <= "2022-02-20") %>%
  group_by(iso3c) %>%
  filter(date == max(date)) %>%
  summarise(date1 = date,
            fully_vaccinated_pct = fully_vaccinated_pct)

maxFeb_map <- merge(geo, maxFeb,  
                  by = "iso3c",
                  all.x = T)

ggplot(data = maxFeb_map) +
    geom_sf(aes(fill = fully_vaccinated_pct)) +
  scale_fill_viridis_c(trans = "sqrt") +
  # customize legend title
  labs(fill = "% fully vaccinated")

This visualization can be expanded through the use of animation. Using animation, we can show how the data evolves over a period of time in an effective manner, allowing for greater understanding of the changes occurring.

dates <- seq(as.Date("2021-04-01"),length=6,by="week")

animate_df <- filter(covid_map, date %in% dates)

ggplot(data = animate_df, aes(group = country)) +
    geom_sf(aes(fill = vaccinated_pct)) +
  scale_fill_viridis_c(option = "plasma", na.value="gray99", trans = "sqrt") +
  transition_states(date, transition_length = 1, state_length = 1, wrap = F)+
  labs(fill = "% fully vaccinated")

Finally, we can show the change in vaccination rates in the form of a Dumbbell plot. A Dumbbell plot will enable us to simultaneously show two different values for each country, in this case being the percentage of individuals fully vaccinated from September of 2021 to January of 2022. We will first extract these two values for each data and situate them in separate columns.

g1 <- covid %>%
  select(country, date, fully_vaccinated_pct) %>%
  filter(date <= "2021-09-30") %>%
  drop_na(country, fully_vaccinated_pct) %>%
  group_by(country) %>%
  filter(date == max(date)) %>%
  summarise(date1 = date,
            rate1 = fully_vaccinated_pct)
  
  
g2 <- covid %>%
  select(country, date, fully_vaccinated_pct) %>%
  filter(date <= "2022-01-31") %>%
  drop_na(country, fully_vaccinated_pct) %>%
  group_by(country) %>%
  filter(date == max(date)) %>%
  summarise(date2 = date,
            rate2 = fully_vaccinated_pct)

gdf <- merge(g1, g2, by = "country")

With the necessary data compiled, we can proceed with the Dumbbell visualization.

gg <- ggplot(gdf, 
             aes(x = rate1, xend = rate2, 
                 y=reorder(country, rate2))) +  # sort the data
        geom_dumbbell(color="#a3c4dc", 
                      size = 2, 
                      colour_x="#a3c4dc", 
                      colour_xend = "#0e668b") + 
        labs(x="% fully vaccinated", y=NULL) +
        theme_classic() +
        theme(plot.background=element_rect(fill="#f7f7f7"),
              panel.background=element_rect(fill="#f7f7f7"),
              panel.grid.minor=element_blank(),
              panel.grid.major.y=element_blank(),
              panel.grid.major.x=element_line(),
              axis.ticks=element_blank(),
              legend.position="top",
              panel.border=element_blank())
show(gg)