#This code chunk is for making and displaying knitr tables
Most_County_Cum_Cases <- Daily_Data %>%
slice_max(cases, n = 5) %>%
select(county, cases)
Most_County_Daily_Cases <- Daily_Data %>%
slice_max(new_cases, n = 5) %>%
filter(new_cases > 0) %>%
arrange(-new_cases) %>%
select(county, new_cases)
print_cum <- Most_County_Cum_Cases %>% #print a nice table for daily, cumulative cases
kable(col.names = c("County", "Cases"),
caption = "Daily Cumulative Cases",
format.args = list(big.mark = ',')) %>%
kable_styling("striped", full_width = TRUE, font_size = 16)
(print_cum)
Daily Cumulative Cases
County
|
Cases
|
Los Angeles
|
1,259,361
|
Riverside
|
303,062
|
San Bernardino
|
300,996
|
San Diego
|
283,882
|
Orange
|
274,132
|
print_daily <- Most_County_Daily_Cases %>% #print a nice table for daily cases
kable(col.names = c("County", "Cases"),
caption = "Daily Cases",
format.args = list(big.mark = ',')) %>%
kable_styling("striped", full_width = TRUE, font_size = 16)
(print_daily)
Daily Cases
County
|
Cases
|
Los Angeles
|
1,063
|
Sacramento
|
545
|
San Bernardino
|
360
|
San Francisco
|
258
|
San Diego
|
242
|
#this code chunk if for getting the last 14 days average
Average_14_Day <- Analyzed_Data %>%
left_join(Population_Estimates, by = c("fips" = "fips")) %>%
filter(date > max(date) - 14) %>%
group_by(state, date) %>%
summarize(total_cases_per_100k = sum(cases, na.rm = TRUE) / sum(as.numeric(...20), na.rm = TRUE) * 100000) %>%
ungroup() %>%
group_by(state) %>%
summarize(total_14_day_average = sum(total_cases_per_100k / 14))
print_avg <- Average_14_Day %>%
kable(col.names = c("State", "Cases Per 100k"),
caption = "Last 14 day average of cases per 100,000 people") %>%
kable_material_dark() %>%
kable_styling(full_width = FALSE, font_size = 20, position = "left")
(print_avg)
Last 14 day average of cases per 100,000 people
State
|
Cases Per 100k
|
California
|
9682.515
|
The total number of cases in Californiais 3839640 on 2021-07-12.
The total number of new cases on 2021-07-12 is 4131.
The total number of safe counties in California is 58.
Now let’s look at 4 states comparing new cases.
#this chunk if for ggplotting the first set of facets
New_State_Cases %>%
ggplot(aes(x = date, y = roll_7))+
geom_col(col = "red")+
facet_wrap(~state)+
labs(title = "State Daily COVID Cases",
x = "Date",
y = "Cases",
subtitle = "Data from NY Times COVID cumulative count")
This can be misleading, so let’s look at the data when ajusted by total population.
#redo new state case and plot without doing the roll 7
New_State_Cases_Per_Cap <- COVID %>%
filter(state == c(facet_states)) %>%
filter(county != "Unknown") %>%
group_by(fips) %>%
mutate(new_cases = cases - lag(cases)) %>%
ungroup() %>%
filter(new_cases != "NA") %>%
group_by(state, date) %>%
summarise(total_daily_state_cases = sum(new_cases)) %>%
ungroup()
Manip_Pop_Raw <- Population_Estimates %>%
right_join(New_State_Cases_Per_Cap, by = c("...3" = "state")) %>%
filter(total_daily_state_cases != "NA") %>%
select(date, ...3, total_daily_state_cases, ...20) %>%
mutate(avg_per_cap = total_daily_state_cases / as.numeric(...20)) %>%
ggplot(aes(x = date, y = avg_per_cap))+
geom_col(col = "gold")+
facet_wrap(~...3)+
labs(title = "State Daily COVID Cases Per Capita",
x = "Date",
y = "Cases Per Cap",
subtitle = "Data from NY Times COVID cumulative count")
(Manip_Pop_Raw)
This is helpful, but finding the 7 day average will be more comparable to our previous plot.
#this code chunk is about doin stuff with the population and what now. per kappita, im tired
#let's manipulate population estimate first
Manip_Pop <- Population_Estimates %>%
right_join(New_State_Cases, by = c("...3" = "state")) %>%
filter(roll_7 != "NA") %>%
select(date, ...3, roll_7, ...20) %>%
mutate(avg_per_cap = roll_7 / as.numeric(...20)) %>%
ggplot(aes(x = date, y = avg_per_cap))+
geom_col(col = "gold")+
facet_wrap(~...3)+
labs(title = "State Daily COVID Cases Per 7 Day Average Capita",
x = "Date",
y = "Cases Per Cap Avg",
subtitle = "Data from NY Times COVID cumulative count")
(Manip_Pop)
As can be seen through this second plot what takes into account the number of cases
in relation to the total population, the rates are much more comparable.
This plot is for the weighted average of COVID cases across the US.