Create a map of all the counties in New York. Be sure to title the map and to fill in each county with the total number of COVID19 cases they have seen to date. In addition, draw county borders in white. Use theme_map() and make sure the legend is at the bottom. [Hint: You will need to calculate the total number of cases per county and then join the resulting file with the counties data file to get the latitude/longitudes for the counties.]
library(tidyverse)
library(urbnmapr)
counties %>%
filter(state_abbv == "NY") -> ny.counties
readr::read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv") -> covid
covid %>%
filter(state == "New York") %>%
group_by(county, fips) %>%
summarise(total_cases = sum(cases)) -> cov19
ny.counties %>%
left_join(cov19, by = c("county_fips" = "fips")) -> ny.df
ggplot() +
geom_polygon(
data = ny.df,
aes(x = long, y = lat, group = group, fill = total_cases),
color = "salmon"
) +
coord_fixed(1.3) +
ggthemes::theme_map() +
labs(
title = "Total COVID-19 Cases in New York's Counties",
fill = "No. of Cases"
)Run the following code chunk to load data on the murder, assault and rape rates per 100,000 persons. Urbanpop is the percent of the state population that lives in an urban area.
## [1] "Murder" "Assault" "UrbanPop" "Rape"
Now create a state-level map of the 50 states making sure to use UrbanPop to fill each state. Title the map and place the legend at the bottom.
states %>%
left_join(USArrests, by = c("state_name" = "statename")) -> st.df
ggplot() +
geom_polygon(
data = st.df,
aes(x = long, y = lat, group = group, fill = UrbanPop),
color = "salmon"
) +
coord_fixed(1.3) +
ggthemes::theme_map() +
labs(
title = "Percent of the Population in Urban Areas",
subtitle = "(by State)",
fill = "% Urban"
)