-
Notifications
You must be signed in to change notification settings - Fork 0
/
Covid-19_AK.Rmd
178 lines (149 loc) · 7.77 KB
/
Covid-19_AK.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
---
title: "COVID-19"
author: "Arianna Kazemi"
date: "3/25/2020"
output: html_document
---
```{r include=FALSE}
library(tidyverse)
library(lubridate)
report_03_24 <-read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/03-24-2020.csv"))
```
### Daily Reports
```{r, fig.height=10}
r03_24=subset(report_03_24,Country_Region == "US")
r03_24=r03_24[,-c(1,2,5,6,7,12)]
r03_24=group_by(r03_24, Province_State) %>% summarise(Confirmed=sum(Confirmed), Deaths=sum(Deaths), Recovered=sum(Recovered))
r03_24 %>%
ggplot() +
geom_point(aes(x = Confirmed, y = reorder(Province_State, Confirmed), color="blue")) +
geom_point(aes(x = Deaths, y = reorder(Province_State, Deaths), color="red"))+
scale_color_manual(values =c('red'='red','blue'='blue', 'purple'='purple'), labels = c('Confirmed',"Recovered", 'Deaths'))+
scale_x_continuous(trans='log10')+
xlab("Cases (log10)")+
ylab("State")+
ggtitle("American Cases as of 3-24-20")
```
```{r}
mybreaks = c(1, 20, 100, 1000, 5000)
USmap <- map_data("usa")
us_03_24=report_03_24[!(report_03_24$Province_State %in% c("American Samoa" , "Northern Mariana Islands","Recovered", "Wuhan Evacuee", "Virgin Islands", "Grand Princess", "Guam", "Puerto Rico", "Diamond Princess")),]
us_03_24=subset(us_03_24,Country_Region == "US")
us_03_24=subset(us_03_24,Lat != 0)
ggplot() +
geom_polygon(data = USmap, aes(x=long, y = lat, group = group), fill="grey", alpha=0.3) +
geom_point(data=subset(us_03_24, Country_Region=="US"), aes(x=Long_, y=Lat,size=Confirmed, color=Confirmed),stroke=F, alpha=0.7) +
scale_size_continuous(name="Cases", trans="log", range=c(1,7), breaks=mybreaks, labels = c("1-19", "20-99", "100-999", "1,000-4,999", "5,000+")) +
# scale_alpha_continuous(name="Cases", trans="log", range=c(0.1, 0.9),breaks=mybreaks) +
scale_color_viridis_c(option="inferno",name="Cases", trans="log",breaks=mybreaks, labels = c("1-19", "20-99", "100-999", "1,000-4,999", "5,000+")) +
theme_void() +
guides( colour = guide_legend()) +
labs(caption = "") +
theme(
legend.position = "bottom",
text = element_text(color = "#22211d"),
plot.background = element_rect(fill = "#ffffff", color = NA),
panel.background = element_rect(fill = "#ffffff", color = NA),
legend.background = element_rect(fill = "#ffffff", color = NA)
)+
ggtitle("Confirmed Cases in the US as of 3-24-20")
```
### Time Series
```{r include=FALSE}
time_series_confirmed <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")) %>%
rename(Province.State = "Province/State", Country.Region = "Country/Region")
time_series_confirmed_long <- time_series_confirmed %>%
pivot_longer(-c(Province.State, Country.Region, Lat, Long),
names_to = "Date", values_to = "Confirmed") %>%
group_by(Country.Region,Date) %>%
summarise(Confirmed = sum(Confirmed))
# convert date to data format
time_series_confirmed_long$Date <- mdy(time_series_confirmed_long$Date)
# Thanks to Prof. Chris Sunderland for this code chunk
time_series_recovered <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Recovered.csv")) %>% rename(Province.State = "Province/State", Country.Region = "Country/Region")
time_series_recovered_long <- time_series_recovered %>%
pivot_longer(-c(Province.State, Country.Region, Lat, Long),
names_to = "Date", values_to = "Recovered") %>%
group_by(Country.Region,Date) %>%
summarise(Recovered = sum(Recovered))
time_series_recovered_long$Date <- mdy(time_series_recovered_long$Date)
time_series_deaths <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Deaths.csv")) %>%
rename(Province.State = "Province/State", Country.Region = "Country/Region")
time_series_deaths_long <- time_series_deaths %>%
pivot_longer(-c(Province.State, Country.Region, Lat, Long),
names_to = "Date", values_to = "Deaths") %>%
group_by(Country.Region,Date) %>%
summarise(Deaths = sum(Deaths))
time_series_deaths_long$Date <- mdy(time_series_deaths_long$Date)
```
```{r}
iran=full_join(time_series_deaths_long, time_series_recovered_long, by=c("Country.Region", "Date"))
iran=full_join(iran, time_series_confirmed_long, by=c("Country.Region", "Date"))
iran %>%
filter (Country.Region == "Iran") %>%
ggplot() +
geom_line(aes(x = Date, y = Confirmed, color = "blue"))+
geom_line(aes(x = Date, y = Deaths, color = "red"))+
geom_line(aes(x = Date, y = Recovered, color = "purple"))+
ggtitle("Iran COVID-19 Cases")+
ylab("Count")+
scale_color_manual(values =c('red'='red','blue'='blue', 'purple'='purple'), labels = c('Confirmed',"Recovered", 'Deaths'))
```
```{r}
iran=full_join(time_series_deaths_long, time_series_recovered_long, by=c("Country.Region", "Date"))
iran=full_join(iran, time_series_confirmed_long, by=c("Country.Region", "Date"))
iran %>%
filter (Country.Region == "Italy") %>%
ggplot() +
geom_line(aes(x = Date, y = Confirmed, color = "blue"))+
geom_line(aes(x = Date, y = Deaths, color = "red"))+
geom_line(aes(x = Date, y = Recovered, color = "purple"))+
ggtitle("Italy COVID-19 Cases")+
ylab("Count")+
scale_color_manual(values =c('red'='red','blue'='blue', 'purple'='purple'), labels = c('Confirmed','Recovered', "Deaths"))
```
### Maps
```{r include=FALSE}
library(maps)
library(viridis)
```
```{r}
world <- map_data("world")
mybreaks <- c(1, 20, 100, 1000, 50000)
ggplot() +
geom_polygon(data = world, aes(x=long, y = lat, group = group), fill="grey", alpha=0.3) +
geom_point(data=time_series_deaths, aes(x=Long, y=Lat, size=`2/25/20`, color=`2/25/20`),stroke=F, alpha=0.7) +
scale_size_continuous(name="Cases", trans="log", range=c(1,7), breaks=mybreaks, labels = c("1-19", "20-99", "100-999", "1,000-49,999", "50,000+")) +
# scale_alpha_continuous(name="Cases", trans="log", range=c(0.1, 0.9),breaks=mybreaks) +
scale_color_viridis_c(option="inferno",name="Cases", trans="log",breaks=mybreaks, labels = c("1-19", "20-99", "100-999", "1,000-49,999", "50,000+")) +
theme_void() +
guides( colour = guide_legend()) +
labs(caption = "") +
theme(
legend.position = "bottom",
text = element_text(color = "#22211d"),
plot.background = element_rect(fill = "#ffffff", color = NA),
panel.background = element_rect(fill = "#ffffff", color = NA),
legend.background = element_rect(fill = "#ffffff", color = NA)
)+
ggtitle("Worldwide Deaths")
```
```{r}
ggplot() +
geom_polygon(data = world, aes(x=long, y = lat, group = group), fill="grey", alpha=0.3) +
geom_point(data=time_series_recovered, aes(x=Long, y=Lat, size=`2/25/20`, color=`2/25/20`),stroke=F, alpha=0.7) +
scale_size_continuous(name="Cases", trans="log", range=c(1,7), breaks=mybreaks, labels = c("1-19", "20-99", "100-999", "1,000-49,999", "50,000+")) +
# scale_alpha_continuous(name="Cases", trans="log", range=c(0.1, 0.9),breaks=mybreaks) +
scale_color_viridis_c(option="inferno",name="Cases", trans="log",breaks=mybreaks, labels = c("1-19", "20-99", "100-999", "1,000-49,999", "50,000+")) +
theme_void() +
guides( colour = guide_legend()) +
labs(caption = "") +
theme(
legend.position = "bottom",
text = element_text(color = "#22211d"),
plot.background = element_rect(fill = "#ffffff", color = NA),
panel.background = element_rect(fill = "#ffffff", color = NA),
legend.background = element_rect(fill = "#ffffff", color = NA)
)+
ggtitle("Worldwide Recovery")
```