-
Notifications
You must be signed in to change notification settings - Fork 0
/
country_minning.Rmd
218 lines (178 loc) · 7.04 KB
/
country_minning.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
---
date: "4/29/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(fig.align = "center", fig.width = 8, fig.height=10, echo = FALSE, message=FALSE, warning=FALSE)
```
```{r run code}
library(readr)
library(tidyverse)
library(readxl)
library(zoo)
library(ggthemes)
library(extrafont)
library(kableExtra)
library(lubridate)
my_theme <- theme_clean()
loadfonts(device = "win")
number_of_countries <- 35
number_of_countries2 <- 35
number_of_cols <- 4
tspan <- 120
# excluded_countries <- c("Qatar", "Ecuador")
excluded_countries <- c()
#load data
#load population for countries around the world.
pop_lookup <- read_rds(here::here("pop_country_level.rds")) %>%
mutate(Country_Region = ifelse(Country_Region == "Korea, South", "South Korea", Country_Region))
df1 <- read_csv("data_world_download/COVID-19 Activity.csv",
col_types = cols(REPORT_DATE = col_date(format = "%Y-%m-%d"),
COUNTY_NAME = col_character(), COUNTY_FIPS_NUMBER = col_character(),
PEOPLE_POSITIVE_CASES_COUNT = col_number(),
PEOPLE_POSITIVE_NEW_CASES_COUNT = col_number(),
PEOPLE_DEATH_COUNT = col_number(),
PEOPLE_DEATH_NEW_COUNT = col_number())) %>%
select(Date = REPORT_DATE,
Admin2 = COUNTY_NAME,
Province_State = PROVINCE_STATE_NAME,
Country_Region = COUNTRY_SHORT_NAME,
country_code = COUNTRY_ALPHA_2_CODE,
CONTINENT_NAME,
Cases = PEOPLE_POSITIVE_CASES_COUNT,
Difference = PEOPLE_POSITIVE_NEW_CASES_COUNT,
Deaths = PEOPLE_DEATH_NEW_COUNT,
Cumulative_Deaths = PEOPLE_DEATH_COUNT,
) %>%
group_by(Date, Country_Region) %>%
summarize_if(is.numeric, sum) %>%
left_join(pop_lookup, by = "Country_Region")
n_reginos <- length(unique(df1$Country_Region))
#find factor by cases
order1 <- df1 %>%
ungroup() %>%
group_by(Country_Region) %>%
filter(Date == max(Date)) %>%
select(Country_Region, Cases) %>%
arrange(desc(Cases))
ln <- length(order1$Country_Region)
order1 <- order1 %>%
ungroup() %>%
mutate(orderv = 1:ln) %>%
select(-Cases)
#========================================================
df1 <- df1 %>%
left_join(order1, by = "Country_Region") %>%
ungroup() %>%
mutate(Country_Region = factor(Country_Region)) %>%
mutate(Country_Region = fct_reorder(Country_Region, orderv)) %>%
filter(orderv <= 60)
top_countries <- df1 %>%
ungroup() %>%
group_by(Country_Region) %>%
filter(Date == max(Date)) %>%
select(Country_Region, Cases) %>%
ungroup() %>%
top_n(number_of_countries)
df1 <- df1 %>%
filter(Country_Region %in% top_countries$Country_Region)
#daily cases
df1 %>%
ggplot(aes(x = Date, y = Difference, colour = Country_Region)) +
facet_wrap(~ Country_Region, ncol = number_of_cols) +
geom_smooth(se = FALSE) +
geom_segment(aes(x = Date, y = Difference , xend = Date, yend = 0), alpha = 0.3) +
geom_point(aes(x = Date, y = Difference), alpha = 0.4) +
my_theme +
theme(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Daily Cases")
#cumulative cases
df1 %>%
ggplot(aes(x = Date, y = Cases, colour = Country_Region)) +
facet_wrap(~ Country_Region, ncol = number_of_cols) +
geom_smooth(se = FALSE) +
geom_segment(aes(x = Date, y = Cases , xend = Date, yend = 0), alpha = 0.3) +
geom_point(aes(x = Date, y = Cases), alpha = 0.4) +
my_theme +
theme(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Cumulative Cases")
#daily cases, y is free
df1 %>%
ggplot(aes(x = Date, y = Difference, colour = Country_Region)) +
facet_wrap(~ Country_Region, ncol = number_of_cols, scales = "free") +
geom_smooth(se = FALSE) +
geom_segment(aes(x = Date, y = Difference , xend = Date, yend = 0), alpha = 0.3) +
geom_point(aes(x = Date, y = Difference), alpha = 0.4) +
my_theme +
theme(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Daily Cases", subtitle = "Y-axsis is free")
#cases per capita
order2 <- df1 %>%
mutate(Difference_pc = (Difference/population)*100000) %>%
ungroup() %>%
group_by(Country_Region) %>%
top_n(7, Date) %>%
arrange(Country_Region, desc(Difference_pc)) %>%
select(Date, Country_Region, Difference_pc) %>%
group_by(Country_Region) %>%
summarize(Difference_pc = mean(Difference_pc)) %>%
arrange(desc(Difference_pc)) %>%
select(Country_Region)
l2 <- length(order2$Country_Region)
order2 <- order2 %>%
mutate(orderlvl2 = 1:l2)
df1 %>%
mutate(Difference_pc = (Difference/population)*100000) %>%
filter(!(Country_Region %in% excluded_countries)) %>%
left_join(order2, by = "Country_Region") %>%
mutate(Country_Region = fct_reorder(Country_Region, orderlvl2)) %>%
ggplot(aes(x = Date, y = Difference_pc, colour = Country_Region)) +
facet_wrap(~ Country_Region, ncol = number_of_cols, scales = "fixed") +
geom_smooth(se = FALSE) +
geom_segment(aes(x = Date, y = Difference_pc , xend = Date, yend = 0), alpha = 0.3) +
geom_point(aes(x = Date, y = Difference_pc), alpha = 0.4) +
ylim(0,75) +
my_theme +
theme(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Daily Cases per 100,000 people",
subtitle = "Arranged by most weekly-average cases per captia ")
df1 %>%
mutate(Difference_pc = (Difference/population)*100000) %>%
ggplot(aes(x = Date, y = Difference_pc, colour = Country_Region)) +
facet_wrap(~ Country_Region, ncol = number_of_cols, scales = "free") +
geom_smooth(se = FALSE) +
geom_segment(aes(x = Date, y = Difference_pc , xend = Date, yend = 0), alpha = 0.3) +
geom_point(aes(x = Date, y = Difference_pc), alpha = 0.4) +
my_theme +
theme(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Daily Cases per 100,000 people", subtitle = "Y-axsis is free")
df1 %>%
filter(Deaths >= 0) %>%
mutate(Deaths_pc = (Deaths/population)*100000) %>%
ggplot(aes(x = Date, y = Deaths_pc, colour = Country_Region)) +
facet_wrap(~ Country_Region, ncol = number_of_cols, scales = "fixed") +
geom_smooth(se = FALSE) +
geom_segment(aes(x = Date, y = Deaths_pc , xend = Date, yend = 0), alpha = 0.3) +
geom_point(aes(x = Date, y = Deaths_pc), alpha = 0.4) +
my_theme +
theme(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Daily Fatalities per 100,000 people")
df1 %>%
filter(Cumulative_Deaths >= 0) %>%
mutate(Cumulative_Deaths_pc = (Cumulative_Deaths/population)*100000) %>%
ggplot(aes(x = Date, y = Cumulative_Deaths_pc, colour = Country_Region)) +
facet_wrap(~ Country_Region, ncol = number_of_cols, scales = "fixed") +
geom_smooth(se = FALSE) +
geom_segment(aes(x = Date, y = Cumulative_Deaths_pc , xend = Date, yend = 0), alpha = 0.3) +
geom_point(aes(x = Date, y = Cumulative_Deaths_pc), alpha = 0.4) +
my_theme +
theme(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Cumulative Fatalities per 100,000 people")
```