-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCOVID19_US_China
More file actions
98 lines (73 loc) · 3.03 KB
/
COVID19_US_China
File metadata and controls
98 lines (73 loc) · 3.03 KB
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
require(RCurl)
require(foreign)
require(tidyverse) # To tip the df from long row of dates to cols (pivot_longer())
x = getURL("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv")
corona = (read_csv(x)
%>% pivot_longer(cols = -c(`Province/State`, `Country/Region`, Lat, Long),
names_to = "date",
values_to = "cases")
%>% select(`Province/State`, `Country/Region`, date, cases)
%>% mutate(date=as.Date(date,format="%m/%d/%y"))
%>% drop_na(cases)
)
united <- corona[corona$`Country/Region`=='US',]
cc_no_states <- united[!united$`Province/State`%in%state.name,]
ccn <- cc_no_states[,2:4]
cc_with_states <- corona[is.element(corona$`Province/State`,state.name),]
cc <- cc_with_states[,2:4]
mix <- rbind(ccn,cc)
mix <- aggregate(mix[,3], FUN="sum", by=list(as.Date(mix$date)))
cc[,2:3] <- mix
cc <- cc[1:nrow(mix),]
china <- corona[corona$`Country/Region`=='China',]
provinces <- c('Hubei', 'Guangdong', 'Henan', 'Zhejiang', 'Hunan', 'Anhui',
'Jiangxi','Shandong','Jiangsu','Sichuan','Heilongjiang','Hebei',
'Fujian','Guangxi','Shaanxi','Yunnan','Hainan','Guizhou','Shanxi',
'Gansu','Hong Kong','Liaoning','Jilin','Xinjiang','Inner Mongolia',
'Ningxia','Qinghai','Macau','Tibet')
china_prov <- china[is.element(china$`Province/State`,provinces),]
ccchina <- china_prov[,2:4]
temp <- aggregate(ccchina[ ,3], FUN="sum", by=list(as.Date(ccchina$date)))
ccchina[,2:3] <- temp
ccchina <- ccchina[1:nrow(temp),]
ccw <- (cc
%>% pivot_wider(names_from=`Country/Region`,values_from="cases")
%>% filter(US>1)
)
ccw_china <- (ccchina
%>% pivot_wider(names_from=`Country/Region`,values_from="cases")
%>% filter(China>1)
)
plot(ccw_china$date, ccw_china$China, type="l", lwd=3, lty=3,
ylab='',
xlab='',
log='y',
col=5,
axes=FALSE,
main = "Log-lin cumulative COVID-19 cases in US v China",
cex.main=0.9)
at1 <- seq(min(ccw_china$date), max(ccw_china$date)+1, by=2);
axis.Date(1, at=at1, format="%b %d", las=2, cex.axis=0.7)
at2 <- 2^seq(1,30,by=1)
axis(side=2, at2, cex.axis=0.7)
abline(h=at2, lty=2, col="grey90") # Add faint grid lines
abline(v=at1, lty=2, col="grey90") # Add faint grid lines
lines(ccw$date, ccw$US, lwd=3, col=4)
legend(ccw_china$date[1], 70000, legend=c("China", "US"),
col=c(5, 4), lty=c(3,1), lwd=3, cex=0.8,
box.lty=0)
plot(ccw_china$date, ccw_china$China, type="l", lwd=3, lty=3,
ylab='',
xlab='',
xaxt="n",
col=5,
cex.axis=0.7,
las=2,
main = "COVID-19 cumulative cases in the US versus China",
cex.main=0.9)
at1 <- seq(min(ccw_china$date), max(ccw_china$date)+1, by=2);
axis.Date(1, at=at1, format="%b %d", las=2, cex.axis=0.7)
lines(ccw$date, ccw$US, lwd=3, col=4)
legend(ccw_china$date[1], 70000, legend=c("China", "US"),
col=c(5, 4), lty=c(3,1), lwd=3, cex=0.8,
box.lty=0)