-
Notifications
You must be signed in to change notification settings - Fork 1
/
X.R
174 lines (165 loc) · 6.3 KB
/
X.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Set Library
library("tidyverse")
library("plyr")
library("dplyr")
library("moments")
library("csv")
library("csvread")
library("readr")
library("rlist")
library("lubridate")
# Set Data
setwd("path") # path
data<-read_csv("owid-covid-data.csv") # data
iso_code<-data[["iso_code"]] # iso_code
continent<-data[["continent"]] # continent
location<-data[["location"]] # location
date<-data[["date"]] # date
new_cases<-data[["new_cases"]] # new_cases
new_deaths<-data[["new_deaths"]] # new_deaths
national<-c("Andorra", "Slovenia", "United Kingdom")
c1_data<-subset(data, location == national[1] & new_cases >= 0 & new_deaths >= 0)
c2_data<-subset(data, location == national[2] & new_cases >= 0 & new_deaths >= 0)
c3_data<-subset(data, location == national[3] & new_cases >= 0 & new_deaths >= 0)
# x> NHOM CAU HOI RIENG
# Processing
# Sorting needed countries (by date)
AND_data <- (data %>% filter_all(any_vars(. %in% c("Andorra"))))
SVN_data <- (data %>% filter_all(any_vars(. %in% c("Slovenia"))))
GBR_data <- (data %>% filter_all(any_vars(. %in% c("United Kingdom"))))
# Sorting needed countries (removing false data)
AND_data<-filter(AND_data,!is.na(AND_data$new_cases)&!is.na(AND_data$new_deaths)&AND_data$new_cases>=0&AND_data$new_deaths>=0,.preserve=FALSE)
SVN_data<-filter(SVN_data,!is.na(SVN_data$new_cases)&!is.na(SVN_data$new_deaths)&SVN_data$new_cases>=0&SVN_data$new_deaths>=0,.preserve=FALSE)
GBR_data<-filter(GBR_data,!is.na(GBR_data$new_cases)&!is.na(GBR_data$new_deaths)&GBR_data$new_cases>=0&GBR_data$new_deaths>=0,.preserve=FALSE)
# Sorting data by date
AND_data %>% arrange(mdy(AND_data$date))
SVN_data %>% arrange(mdy(SVN_data$date))
GBR_data %>% arrange(mdy(GBR_data$date))
# Plotting
# Last 7 days plotting
# New cases
for (i in c(1:3))
{
color<- rgb (208 / 255, 25 / 255, 31 / 255)
if (i == 2)
color<-rgb (15 / 255, 142 / 255, 11 / 255)
else if (i == 3)
color<-rgb (36 / 255, 41 / 255, 172 / 255)
par(mar=c(3.9,3.9,1.5,0.3))
if (i==1)
barplot(AND_data$new_cases[(which.max(mdy(AND_data$date))-6):which.max(mdy(AND_data$date))],
xlab = "Days",
ylab = "New Cases",
main = national[i],
names.arg = AND_data$date[(which.max(mdy(AND_data$date))-6):which.max(mdy(AND_data$date))],
col = color)
else if (i==2)
barplot(SVN_data$new_cases[(which.max(mdy(SVN_data$date))-6):which.max(mdy(SVN_data$date))],
xlab = "Days",
ylab = "New Cases",
main = national[i],
names.arg = SVN_data$date[(which.max(mdy(SVN_data$date))-6):which.max(mdy(SVN_data$date))],
col = color)
else if (i==3)
barplot(GBR_data$new_cases[(which.max(mdy(GBR_data$date))-6):which.max(mdy(GBR_data$date))],
xlab = "Days",
ylab = "New Cases",
main = national[i],
names.arg = GBR_data$date[(which.max(mdy(GBR_data$date))-6):which.max(mdy(GBR_data$date))],
col = color)
}
# New deaths
for (i in c(1:3))
{
color<- rgb (208 / 255, 25 / 255, 31 / 255)
if (i == 2)
color<-rgb (15 / 255, 142 / 255, 11 / 255)
else if (i == 3)
color<-rgb (36 / 255, 41 / 255, 172 / 255)
par(mar=c(3.9,3.9,1.5,0.3))
if (i==1)
barplot(AND_data$new_deaths[(which.max(mdy(AND_data$date))-6):which.max(mdy(AND_data$date))],
xlab = "Days",
ylab = "New Deaths",
main = national[i],
names.arg = AND_data$date[(which.max(mdy(AND_data$date))-6):which.max(mdy(AND_data$date))],
col = color)
else if (i==2)
barplot(SVN_data$new_deaths[(which.max(mdy(SVN_data$date))-6):which.max(mdy(SVN_data$date))],
xlab = "Days",
ylab = "New Deaths",
main = national[i],
names.arg = SVN_data$date[(which.max(mdy(SVN_data$date))-6):which.max(mdy(SVN_data$date))],
col = color)
else if (i==3)
barplot(GBR_data$new_deaths[(which.max(mdy(GBR_data$date))-6):which.max(mdy(GBR_data$date))],
xlab = "Days",
ylab = "New Deaths",
main = national[i],
names.arg = GBR_data$date[(which.max(mdy(GBR_data$date))-6):which.max(mdy(GBR_data$date))],
col = color)
}
# General plotting
# New case plotting
for (i in c(1:3))
{
color<- rgb (208 / 255, 25 / 255, 31 / 255)
if (i == 2)
color<-rgb (15 / 255, 142 / 255, 11 / 255)
else if (i == 3)
color<-rgb (36 / 255, 41 / 255, 172 / 255)
par(mar=c(3.9,3.9,1.5,0.3))
if (i==1)
barplot(AND_data$new_cases[1:which.max(mdy(AND_data$date))],
xlab = "Days",
ylab = "New Cases",
main = national[i],
names.arg = AND_data$date[1:which.max(mdy(AND_data$date))],
col = color)
else if (i==2)
barplot(SVN_data$new_cases[1:which.max(mdy(SVN_data$date))],
xlab = "Days",
ylab = "New Cases",
main = national[i],
names.arg = SVN_data$date[1:which.max(mdy(SVN_data$date))],
col = color)
else if (i==3)
barplot(GBR_data$new_cases[1:which.max(mdy(GBR_data$date))],
xlab = "Days",
ylab = "New Cases",
main = national[i],
names.arg = GBR_data$date[1:which.max(mdy(GBR_data$date))],
col = color)
}
# New deaths plotting
for (i in c(1:3))
{
color<- rgb (208 / 255, 25 / 255, 31 / 255)
if (i == 2)
color<-rgb (15 / 255, 142 / 255, 11 / 255)
else if (i == 3)
color<-rgb (36 / 255, 41 / 255, 172 / 255)
par(mar=c(3.9,3.9,1.5,0.3))
if (i==1)
barplot(AND_data$new_deaths[1:which.max(mdy(AND_data$date))],
xlab = "Days",
ylab = "New Deaths",
main = national[i],
names.arg = AND_data$date[1:which.max(mdy(AND_data$date))],
col = color)
else if (i==2)
barplot(SVN_data$new_deaths[1:which.max(mdy(SVN_data$date))],
xlab = "Days",
ylab = "New Deaths",
main = national[i],
names.arg = SVN_data$date[1:which.max(mdy(SVN_data$date))],
col = color)
else if (i==3)
barplot(GBR_data$new_deaths[1:which.max(mdy(GBR_data$date))],
xlab = "Days",
ylab = "New Deaths",
main = national[i],
names.arg = GBR_data$date[1:which.max(mdy(GBR_data$date))],
col = color)
}
rm(i,color)