-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_0317.Rmd
147 lines (123 loc) · 4.75 KB
/
index_0317.Rmd
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
title: "COVID-19 World and US View"
description: |
Stay home, safe a life.
site: distill::distill_website
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
install.load::install_load(c('distill','dplyr', 'tidyverse', 'ggplot2', 'plotly', 'rmarkdown', 'magrittr', 'RCurl', 'lubridate', 'DT', 'ggthemes'))
```
This main page is a dashboard being built, which may be refreshed in the future. **Last updated `r format(lubridate::now("US/Pacific"), '%a, %b %d %I:%M %p')`** PST.
See "Analyses" tab for analyses performed.
## World View
```{r}
fp_data = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv'
# Read in data
dfc = read_csv(fp_data) %>%
select(-Lat, -Long) %>%
gather(date_raw, confirmed,
-`Province/State`, -`Country/Region`) %>%
mutate(date = mdy(date_raw))
# Clean column names
colnames(dfc) %<>%
tolower() %>%
str_replace_all(fixed('/'), '_') %>%
str_replace_all(fixed(' '), '_')
ggplot2::theme_set(theme_minimal())
```
```{r}
# Day since 1
df_sum <- dfc %>%
group_by(country_region, date) %>%
summarize(confirmed = sum(confirmed)) %>%
arrange(country_region, date)
df_tmp <- df_sum %>%
filter(confirmed > 0) %>%
mutate(day_since_start = row_number()) %>%
ungroup() %>%
#filter(country_region %in% c("China", 'US', 'Italy', 'France', 'Iran')) %>% #View
highlight_key(~country_region)
p <- ggplot(df_tmp, aes(x=day_since_start,
y=confirmed,
color=country_region)) +
geom_line() +
labs(title='Total Confirmed COVID-19 Cases by Days Since First Onset',
x = 'Days Since Start of Onset',
y = 'Total Confirmed') +
theme(legend.position = "none")
ggplotly(p) %>%
highlight('plotly_hover',
selectize = T,
# dynamic=T,
defaultValues = c('China', 'Italy', 'US'))
```
## Countries with more than 3,000
The X-axis is days since hitting 3,000 cases.
```{r}
df_plotly <- df_sum %>%
filter(confirmed > 3000) %>%
mutate(days_since = row_number(),
days_since = ifelse(country_region == 'US', days_since - 1 , days_since)) %>%
ungroup() %>%
highlight_key(~country_region)
p <- ggplot(df_plotly, aes(x = days_since, y = confirmed, group = country_region, text = date), color = palette_pander(7)[7]) +
geom_line() +
labs(title='Countries with More than 3,000 Cases',
x = 'Days Since Hitting 3000 Confirmed Cases',
y = 'Total Confirmed Cases',
caption = 'Data Source: github.com/CSSEGISandData/COVID-19\ngithub.com/bryanwhiting/covid19')
ggplotly(p, tooltip = c('days_since', 'confirmed', 'country_region', 'date')) %>%
highlight('plotly_click', color=palette_pander(6),
dynamic=T,
default = 'Italy')
```
## US States Since March 1
This interactive plot shows the states that are starting to follow the trend of doubling every two days.
```{r}
# Prepare a dataframe by state. Some data processing needs to happen.
df_state <- dfc %>%
filter(country_region == 'US',
confirmed > 0) %>%
group_by(province_state) %>%
arrange(date) %>%
mutate(days_since_first = row_number()) %>%
arrange(province_state, date) %>%
mutate(state2 = str_extract(province_state, '[A-Z][A-Z]$'),
state2 = ifelse(is.na(state2), province_state, state2)) %>%
ungroup() %>%
select(state2, date, confirmed) %>%
left_join(tibble(state_abb = state.abb, state2=state.name),
by='state2') %>%
mutate(state = ifelse(is.na(state_abb), state2, state_abb)) %>%
select(state, date, confirmed)
# df_state %>%
# filter(state != 'Diamond Princess') %>%
# mutate(state = ifelse(str_detect(state, 'District|D.C.'), 'DC', state)) %>%
# group_by(state) %>%
# arrange(date) %>%
# summarize(confirmed = sum(confirmed))
# Check to see how counties were aggregated
# dfc %>%
# filter(str_detect(province_state, ', CA|California')) %>%
# mutate(state = province_state == 'California') %>%
# group_by(state, date) %>%
# summarize(confirmed = sum(confirmed)) %>%
# arrange(date, state) %>%
# View()
df_plt = df_state %>%
filter(date >= '2020-03-01') %>%
ungroup() %>%
highlight_key(~state)
p <- ggplot(df_plt, aes(x = date, y = confirmed, group=state)) +
geom_line() +
scale_x_date(labels = scales::date_format("%m/%d")) +
labs(title='Confirmed Cases in US States Since March 1',
x = 'Date',
y = 'Total Confirmed Cases',
caption = 'Data Source: github.com/CSSEGISandData/COVID-19\ngithub.com/bryanwhiting/covid19')
ggplotly(p, tooltip = c('state', 'confirmed', 'date')) %>%
highlight('plotly_click', color=palette_pander(6),
dynamic=T, default = 'NY')
```
> Tip: The plots are clickable. Hold shift while clicking to show multiple lines.