-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#COVID19-plots.R
67 lines (34 loc) · 2.18 KB
/
#COVID19-plots.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
#COVID19-plots
library(stringr)
library(dplyr)
library(ggplot2)
library(reshape2)
library(ggrepel)
library(directlabels)
confirm=read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")
dead=read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv")
recover=read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv")
country <- ifelse(is.na(confirm[,1])==TRUE, "", paste(confirm[,2], confirm[,1]))
country=str_squish(country)
confirm.1=data.frame(country, confirm[,5:ncol(confirm)], status="confirm")
country.dead <- ifelse(is.na(dead[,1])==TRUE, "", paste(dead[,2], dead[,1]))
country.dead=str_squish(country.dead)
dead.1=data.frame(country.dead, dead[,5:ncol(dead)], status="dead")
country.recover <- ifelse(is.na(recover[,1])==TRUE, "", paste(recover[,2], recover[,1]))
country.recover=str_squish(country.recover)
recover.1=data.frame(country.recover, recover[,5:ncol(recover)], status="recover")
names(dead.1)=names(recover.1)=names(confirm.1)
merge=rbind(confirm.1, dead.1, recover.1)
merge.melt=melt(merge, id.vars=c("country", "status"))
merge.melt$log_val=log(merge.melt$value, base = exp(1))
merge.melt[mapply(is.infinite, merge.melt)] <- 0
merge.melt$variable=sub("X", "", merge.melt$variable)
merge.melt$variable=as.Date(merge.melt$variable, format='%m.%d.%y')
colnames(merge.melt)=c("Country", "Status", "Date", "Cases", "log_cases")
head(merge.melt)
#merge.melt[merge.melt[,1]=="US",]
my_con=c("Italy", "Israel", "US")
merge.melt.con=merge.melt[merge.melt[,1]==my_con,]
#ploting
p=ggplot(merge.melt.con, aes(x=Date, y=log_cases))+geom_point(aes(x=Date, y=log_cases, group=Country, colour=Country), alpha=0.5)+geom_smooth(aes(x=Date, y=log_cases, group=Country, colour=Country), method="loess")+facet_grid(~Status, scales='free_y')+theme_bw()+scale_x_date(expand = c(.1, .1))
direct.label(p, method="last.points")