-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFig2a_case_count_tianjin.Rmd
82 lines (57 loc) · 2.85 KB
/
Fig2a_case_count_tianjin.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
---
title: "Singapore figures"
author: "Venus Lau; Lauren Tindale"
output:
html_document:
keep_md: TRUE
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(viridis)
library(dplyr)
library(plotly)
library(scales)
data <- read.csv("data/COVID-19_Tianjin_confirmed_discharges.csv", header = TRUE, na.strings=c("","NA"))
data$date <- as.Date(data$date, "%d/%m/%Y")
```
#Calculate average duration between exposure, symptom onset, hospitaization, and discharge
```{r}
data_master <- read.csv("data/COVID-19_Tianjin.csv", header = TRUE, na.strings=c("","NA"))
data_master$symptom_onset <- as.Date(data_master$symptom_onset, "%d/%m/%Y")
data_master$confirm_date <- as.Date(data_master$confirm_date, "%d/%m/%Y")
data_master$start_source <- as.Date(data_master$start_source, "%d/%m/%Y")
data_master$end_source <- as.Date(data_master$end_source, "%d/%m/%Y")
data_master$days_between_inf_symp = difftime(data_master$symptom_onset, data_master$end_source, units = "days")
data_master$days_between_symp_conf = difftime(data_master$confirm_date, data_master$symptom_onset, units = "days")
mean_sd<-data_master %>% select(days_between_inf_symp:days_between_symp_conf) %>% summarise_all(list(mean=mean, sd=sd), na.rm=TRUE)
```
```{r cases by date}
cols <- c("Cumulative confirmed"="#440154FF", "Cumulative discharged"="#1F968BFF", "Death per day"="#FDE725FF", "Confirmed per day"="#39568CFF")
p<-data %>%
ggplot() +
geom_bar(aes(x = date, y=confirmed), fill = "#39568CFF", stat="identity") +
geom_line(aes(x = date, y = total_confirmed, color = "Cumulative confirmed"), size = 1) +
geom_bar(aes(x = date, y=deaths), width = 0.5, fill = "#FDE725FF", stat="identity") +
geom_line(aes(x = date, y = total_discharge, color = "Cumulative discharged"), size = 1) +
geom_blank(aes(color = "Confirmed per day")) +
geom_blank(aes(color = "Death per day")) +
xlab(label = "Date") +
ylab(label = "Number of Cases") +
ggtitle(label = "Tianjin COVID-19 Cases") +
theme(plot.title = element_text(hjust = 0.5, size=16)) + #centre main title
theme(axis.text.x = element_text(angle =60, hjust = 1, size = 8),
axis.title = element_text(size=14),
axis.ticks.x = element_blank(), #remove x axis ticks
axis.ticks.y = element_blank(),
legend.text=element_text(size=12),
legend.title = element_text(size=14)) + #remove y axis ticks
scale_x_date(date_breaks = "day") +
scale_y_continuous(breaks=pretty_breaks(n=20)) +
scale_colour_manual(name = "Legend", values = cols) +
theme(panel.background = element_rect(fill = "white"))+
annotate(geom="text", x=as.Date("2020-02-22"), y=135, label="135", hjust="left") +
annotate(geom="text", x=as.Date("2020-02-22"), y=65, label="65", hjust="left")
p
#ggsave("final_figures/Fig2a_case_count_tianjin.pdf",plot=p, device="pdf",width = 10,height = 7.4,units="in")
```