-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.R
157 lines (128 loc) · 4.63 KB
/
global.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
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
library(readr)
library(plyr)
library(plotly)
library(dplyr)
library(shiny)
library(shinythemes)
library(shinyjs)
# get the data from the john hopkins github repository (data provided by who)
confirmed <-
"https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
confirmed_data <-
as.data.frame(read_csv(url(confirmed), col_types = cols()))
confirmed_data$`Country/Region` <-
data.table::fifelse(
is.na(confirmed_data$`Province/State`),
confirmed_data$`Country/Region`,
paste0(
confirmed_data$`Country/Region`,
" ",
"(",
confirmed_data$`Province/State`,
")"
)
)
deaths <-
"https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv"
death_data <-
as.data.frame(read_csv(url(deaths), col_types = cols()))
death_data$`Country/Region` <-
data.table::fifelse(
is.na(death_data$`Province/State`),
death_data$`Country/Region`,
paste0(
death_data$`Country/Region`,
" ",
"(",
death_data$`Province/State`,
")"
)
)
recovered <-
"https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv"
recover_data <-
as.data.frame(read_csv(url(recovered), col_types = cols()))
recover_data$`Country/Region` <-
data.table::fifelse(
is.na(recover_data$`Province/State`),
recover_data$`Country/Region`,
paste0(
recover_data$`Country/Region`,
" ",
"(",
recover_data$`Province/State`,
")"
)
)
# get the global time series
# confirmed case
global_conf <- select(confirmed_data, -c(1, 3, 4))
global_conf <- as.data.frame(t(global_conf))
global_conf_u <- global_conf[2:nrow(global_conf),]
gdate <- global_conf_u
global_conf_u <- data.frame(apply(global_conf_u, 2, as.numeric))
global_conf_u$Date <-
as.Date(row.names(gdate), format = "%m/%d/%y")
names(global_conf_u) <- c(confirmed_data$`Country/Region`, "Date")
global_conf_u <-
mutate(global_conf_u, global = rowSums(global_conf_u[, 1:(ncol(global_conf_u) -
1)]))
# deaths
global_death <- select(death_data, -c(1, 3, 4))
global_death <- as.data.frame(t(global_death))
global_death_u <- global_death[2:nrow(global_death),]
gdate <- global_death_u
global_death_u <- data.frame(apply(global_death_u, 2, as.numeric))
global_death_u$Date <-
as.Date(row.names(gdate), format = "%m/%d/%y")
names(global_death_u) <- c(death_data$`Country/Region`, "Date")
global_death_u <-
mutate(global_death_u, global = rowSums(global_death_u[, 1:(ncol(global_death_u) -
1)]))
# recovery
global_recov <- select(recover_data, -c(1, 3, 4))
global_recov <- as.data.frame(t(global_recov))
global_recov_u <- global_recov[2:nrow(global_recov),]
gdate <- global_recov_u
global_recov_u <- data.frame(apply(global_recov_u, 2, as.numeric))
global_recov_u$Date <-
as.Date(row.names(gdate), format = "%m/%d/%y")
names(global_recov_u) <- c(recover_data$`Country/Region`, "Date")
global_recov_u <-
mutate(global_recov_u, global = rowSums(global_recov_u[, 1:(ncol(global_recov_u) -
1)]))
# get the global summary
confirmed_cases <- sum(confirmed_data[, ncol(confirmed_data)])
deaths <- sum(death_data[, ncol(death_data)])
recovered <- sum(recover_data[, ncol(recover_data)])
# filter only bangladesh data
bangladesh_confirmed <-
filter(confirmed_data, confirmed_data[, 2] == "Bangladesh")
bangladesh_death <-
filter(death_data, death_data[, 2] == "Bangladesh")
bangladesh_recover <-
filter(recover_data, recover_data[, 2] == "Bangladesh")
bangladesh_data <-
bind_rows(bangladesh_confirmed, bangladesh_death, bangladesh_recover)
# keep only the required columns
bangladesh_data <-
select(bangladesh_data, c(5:ncol(bangladesh_data)))
# turn the data long from wide
bangladesh_data <- as.data.frame(t(bangladesh_data))
# rename the columns
bangladesh_data <-
rename(
bangladesh_data,
Confirmed = V1,
Deaths = V2,
Recovered = V3
)
# get the dates and format the column
bangladesh_data$Date <- row.names(bangladesh_data)
bangladesh_data$Date <-
as.Date(bangladesh_data$Date, format = "%m/%d/%y")
bangladesh_data <- na_if(bangladesh_data, 0)
# get the list of the available countries
country_list <- confirmed_data$`Country/Region`
# remove bangladesh from the available counties (as it is the base country)
country_list <- country_list %>% .[. != "Bangladesh"]