pacman::p_load(tidyverse, usmap, install = FALSE, update = FALSE)
load("G:/My Drive/homework/Cooper P/MA_county_variables_2020.Rdata")
load("G:/My Drive/homework/Cooper P/MA_COVID19_21_02_16.Rdata")
ma_extra <- ma_extra %>% as_tibble()
#
ma_extra %>% dim()
## [1] 14 24
# nearby is a subset of mass
nearby %>% intersect(mass) %>% dim(); nearby %>% dim()
## [1] 669 10
## [1] 669 10
mass %>% dim()
## [1] 5134 10
# total_nearby is not a subset of mass_totals
total_nearby %>% intersect(mass_totals) %>% dim(); total_nearby %>% dim()
## [1] 0 7
## [1] 335 7
totals <- total_nearby %>% union(mass_totals)
totals %>% dim()
## [1] 716 7
# MA data
mass_join <- mass %>% left_join(ma_extra)
## Joining, by = "county"
mass_join %>% dim()
## [1] 5134 33
mass %>%
filter(new_cases >= 0) %>%
ggplot(aes(date, new_cases)) +
geom_point() +
facet_wrap(vars(county)) +
labs(title = "New MA COVID Cases by County",
subtitle = "Fixed Scales",
x = "Date",
y = "Cases") +
theme(axis.text.x=element_text(angle = 90, hjust = 0))
mass %>%
filter(new_cases >= 0) %>%
ggplot(aes(date, new_cases)) +
geom_point() +
facet_wrap(vars(county), scales = "free_y") +
labs(title = "New MA COVID Cases by County",
subtitle = "Free Scales",
x = "Date",
y = "Cases") +
theme(axis.text.x=element_text(angle = 90, hjust = 0))
to_string <- as_labeller(c(`Rural_urban_Continuum_Code_2013` = "Rural Urban Continuum",
`Urban_Influence_Code_2013` = "Urban Influence"))
ma_extra %>%
select(contains("2013")) %>%
gather() %>%
ggplot(aes(value)) +
geom_bar() +
facet_wrap(vars(key),labeller = to_string) +
labs(title = "2013 Codes", x = "Category")
ma_extra %>%
select(contains("2013")) %>%
gather() %>%
ggplot(aes(value, fill = key)) +
geom_bar() +
labs(title = "2013 Codes", x = "Category", fill = "") +
scale_fill_discrete(labels = c("Rural Urban Continuum", "Urban Influence"))
mass %>%
select(county, cases) %>%
group_by(county) %>%
summarize(cases = sum(cases)) %>%
ggplot(aes(county, cases)) +
geom_col() +
theme(axis.text.x=element_text(angle = 90, hjust = 0)) +
labs(title = "MA COVID Cases by County", x = "", y = "")
ma_extra %>%
ggplot(aes(Urban_rural %>% str_to_title(), people_per_Housing)) +
geom_boxplot(varwidth = TRUE) +
labs(title = "People per Dwelling", x = "", y = "Density")
mass %>%
filter(new_cases >= 0) %>%
ggplot(aes(county, new_cases)) +
geom_boxplot(varwidth = TRUE) +
theme(axis.text.x=element_text(angle = 90, hjust = 0)) +
labs(title = "MA New Cases by County", x = "", y = "")
nearby %>%
filter(new_cases >= 0) %>%
ggplot(aes(county, new_cases)) +
geom_boxplot() +
labs(title = "MA New Cases For Two Counties", x = "", y = "")
nearby %>%
filter(new_cases >= 0) %>%
ggplot(aes(county, new_cases)) +
geom_violin() +
labs(title = "MA New Cases For Two Counties", x = "", y = "")
https://github.com/pdil/usmap/blob/master/README.md
mass %>%
filter(new_cases >= 0) %>%
group_by(fips) %>%
summarize(New_Cases = mean(new_cases)) %>%
# drop_na() %>%
plot_usmap(regions = "counties",
include = "MA",
data = .,
values = "New_Cases",
color = "blue",
labels = TRUE) +
scale_fill_continuous(name = "Average New Cases") +
theme(legend.position = "right")
mass %>%
filter(new_deaths >= 0) %>%
group_by(fips) %>%
summarize(New_Deaths = mean(new_deaths)) %>%
# drop_na() %>%
plot_usmap(regions = "counties",
include = "MA",
data = .,
values = "New_Deaths",
color = "blue",
labels = TRUE) +
scale_fill_continuous(name = "Average New Deaths") +
theme(legend.position = "right")