TUTO MUS BE FAMILIAR WITH RSTUDIO
INTRO
For this week’s homework, let’s work on mapping the covid-19 data. You have two choices of data source. The first is the coronavirus data we have already loaded.
library(coronavirus)
head(coronavirus)
## Province.State Country.Region Lat Long date cases type
## 1 Japan 35.67620 139.6503 2020-01-22 2 confirmed
## 2 South Korea 37.56650 126.9780 2020-01-22 1 confirmed
## 3 Thailand 13.75630 100.5018 2020-01-22 2 confirmed
## 4 Anhui Mainland China 31.82571 117.2264 2020-01-22 1 confirmed
## 5 Beijing Mainland China 40.18238 116.4142 2020-01-22 14 confirmed
## 6 Chongqing Mainland China 30.05718 107.8740 2020-01-22 6 confirmed
The second is a newer dataset. It harvests data that is from the New York Times. It is focused solely on the US. To install it, you’ll need to do the following
#if you don't have it already
install.packages("devtools")
#install the library from github
devtools::install_github("covid19R/covid19nytimes")
library(covid19nytimes)
covid_states <- refresh_covid19nytimes_states()
head(covid_states)
## # A tibble: 6 x 7
## date location location_type location_standa… location_standa… data_type
## <date> <chr> <chr> <chr> <chr> <chr>
## 1 2020-01-21 Washing… state 53 fips_code cases_to…
## 2 2020-01-21 Washing… state 53 fips_code deaths_t…
## 3 2020-01-22 Washing… state 53 fips_code cases_to…
## 4 2020-01-22 Washing… state 53 fips_code deaths_t…
## 5 2020-01-23 Washing… state 53 fips_code cases_to…
## 6 2020-01-23 Washing… state 53 fips_code deaths_t…
## # … with 1 more variable: value <dbl>
covid_counties <- refresh_covid19nytimes_counties()
head(covid_counties)
## # A tibble: 6 x 7
## date location location_type location_standa… location_standa… data_type
## <date> <chr> <chr> <chr> <chr> <chr>
## 1 2020-01-21 Snohomi… county_state 53061 fips_code cases_to…
## 2 2020-01-21 Snohomi… county_state 53061 fips_code deaths_t…
## 3 2020-01-22 Snohomi… county_state 53061 fips_code cases_to…
## 4 2020-01-22 Snohomi… county_state 53061 fips_code deaths_t…
## 5 2020-01-23 Snohomi… county_state 53061 fips_code cases_to…
## 6 2020-01-23 Snohomi… county_state 53061 fips_code deaths_t…
## # … with 1 more variable: value <dbl>
Now, you have three data sets to choose from! Countries, states, or counties. Remember, with the coronavirus data, you have to do some dplyr::summarizing to get it down to countries, though!
Maps to use for this assignment
OK, so, we need world, US state, and US county maps – depending on which of the three datasets you chose
library(sf)
## Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
#The world
library(rnaturalearth)
world_map <- ne_countries()
#US States
library(USAboundaries)
us_states <- us_states()
#US Counties
us_counties <- us_counties()
Armed with this, let’s make some maps!
QUESTIONS
- Which data set – or aspect of a single data set, are you most interested in? Sort through the datasets. What is there? Is it the world? A single country? Multiple contries? All states? Counties in one state?
Filter or summarize your data to just what you are interested in, in terms of space.
For example
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
florida_covid <- covid_counties %>%
filter(stringr::str_detect(location, "[Ff]lorida"))
florida_map <- us_counties %>%
filter(state_name == "Florida")
- What type or types of data from that dataset are you interested in? Why? Filter the dataset to that data type only.
- What do you want to learn from this slice of the data? Formulate a question and write it out here.
- Filter and manipulate the data so that it is in a format to be used to answer the question.
- Join the covid data with spatial data to build a map.
- Create a map from this data! Make it awesome!
- What do you learn from the map you made?
- This static map is, I’m sure, great. Load up
tmapand make it dynamic! Is there anything different you can learn from this form of visualization?


0 comments