-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcovidtracking_script.R
84 lines (69 loc) · 2.04 KB
/
covidtracking_script.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
library(readr)
library(tidyverse)
library(ggpubr)
library(covid19us)
library(geofacet)
library(gganimate)
library(paletteer)
#https://api.covidtracking.com/v1/states/daily.csv
us_pop <-
daily <- get_states_daily()
df2 <- daily %>%
filter(state %in% c("CA", "NY", "IL")) %>%
select(date,
state,
positive,
positive_tests_people_antigen,
total_test_results,
total_test_results_source,
hospitalized_currently,
on_ventilator_currently,
death_confirmed,
death_increase,
total_tests_people_viral,
recovered,
in_icu_currently
) %>%
ggplot(aes(x = date, y = hospitalized_currently, color = state)) +
geom_point() +
geom_line() +
facet_wrap(~ state) +
scale_y_continuous(labels = scales::comma) +
theme_pubclean() +
theme(legend.position = "none")
# transition_reveal(date, keep_last = FALSE)
# facet_wrap(~ state , scales = "fixed") +
# nframes = [...or pick it here])
df2
# run by metric -----------------------------------------------------------
df3 <- daily %>%
filter(state %in% c("SC", "OH", "NC")) %>%
select(date,
state,
positive_increase,
positive,
total_test_results,
hospitalized_currently,
death_increase,
in_icu_currently
) %>%
gather(metric, value, -date, -state) %>%
ggplot(aes(x = date, y = value, colour = state)) +
geom_line() +
geom_smooth(se = FALSE) +
facet_wrap(~ metric, scales = "free") +
scale_y_continuous(labels = scales::comma) +
scale_color_paletteer_d("yarrr::southpark") +
theme_pubclean()
# theme(legend.position = "bottom") +
# transition_reveal(date, keep_last = FALSE)
df3
# geo facet ---------------------------------------------------------------
df4 <- daily %>%
select(date, state, hospitalized_currently) %>%
filter(date > "2020-08-01") %>%
ggplot(aes(x = date, y = hospitalized_currently)) +
geom_line() +
facet_geo(~ state) +
theme_pubclean()
df4