Getting started

  1. Clone your repo appex04-[github_name] to create a new project in RStudio Cloud under the STA 199 class space.

  2. Configure git

    use_git_config("your name","your email")

Packages and Data

We’ll make use of the following packages.


There are two data files we will use: world.shp, coronavirus.shp. We’ll read each of these in with function st_read() and save them as world and virus.

world <- st_read("data/world.shp", quiet = TRUE)
virus <- st_read("data/coronavirus.shp", quiet = TRUE)


Task 1

Take a look at objects world and virus. How many fields exist for each object? What type of geometry is associated with each sf object?


Task 2

Part 1

Use object world to create a world map of the countries. You’ll want to use functions ggplot() and geom_sf().

Part 2

Build on your map from Part 1 so that the countries have a fill color associated with the population estimate. Variable pop_est is in millions. Be sure to label your map.

Task 3

Filter world for the country “China”. Save the result as china.

china <- world %>% 
  filter(name == "China")

Next, we’ll filter object virus for confirmed cases in China and save the result as china_cv. The code is given below.

china_cv <- virus %>% 
  filter(cntry_r == "Mainland China", !
  • cntry_r == "Mainland China" filters rows so we only keep information on China

  • ! filters rows for where there is not a missing confirmed case of coronavirus

Task 4

Use the template provided to overlay the point locations of the coronavirus in China with a map of China. Have the size of the points reflect the number of confirmed cases. Refer to slides 31-32 as a guide.

ggplot(data = china) +
  geom_sf(fill = "#DE2910")