/
plot_raw_est_cases_together.R
53 lines (45 loc) · 1.88 KB
/
plot_raw_est_cases_together.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
library(data.table)
library(lubridate)
library(ggplot2)
library(EpiNow2)
.debug <- "C:/Users/alice/Documents/GitHub/rt_data/analysis/" ## remember to change this line to your local directory
.args <- if (interactive()) sprintf(c(
"%s/jhu-case_timeseries_clean.rds",
"%s/rt_init.rds",
"%s/fig_cases_rt_raw_estimate.png"
), .debug[1]) else commandArgs(trailingOnly = TRUE)
cd <- readRDS(.args[1])
est_case <- readRDS(.args[2])
cols <- c("date", "median")
est_case <- summary(est_case, type="parameters", "estimated_reported_cases")
est_case <- est_case[, ..cols]
cd[, date := as.Date(date)]
cd <- cd[between(date, as.Date("2020-11-01"), as.Date("2021-02-07"))]
cols <- c("date", "new_case")
cd <- cd[, ..cols]
# setnames(cd, c("date", "metric"))
# cd[, estimate := rep("Cases", nrow(cd))]
setnames(cd, c("date", "incidence"))
est_case[, est_case := est_case[, "median"]]
#plot with 7-day avg
p <- ggplot(data = cd, aes(x = date))+
geom_point(data = cd, aes(y = incidence), color = "#F8766D", size = 1.5) +
geom_line(data = est_case, aes(y = frollmean(est_case, 7, align = "center")), color = "#6d79f8", lwd = 1) +
ggtitle(label = "Kenya Raw and Estimated Cases") +
scale_y_log10(name="Incidence")+
scale_x_date(name=NULL, date_breaks = "months", date_labels = "%b '%y") +
coord_cartesian(expand = FALSE) +
theme_minimal()
p
ggsave("overlay_raw_est_case_7day.png", p, width = 16, height = 9)
#plot with simple est
p <- ggplot(data = cd, aes(x = date))+
geom_point(data = cd, aes(y = incidence), color = "#F8766D", size = 1.5) +
geom_line(data = est_case, aes(y = est_case), color = "#6d79f8", lwd = 1) +
ggtitle(label = "Kenya Raw and Estimated Cases") +
scale_y_log10(name="Incidence")+
scale_x_date(name=NULL, date_breaks = "months", date_labels = "%b '%y") +
coord_cartesian(expand = FALSE) +
theme_minimal()
p
ggsave("overlay_raw_est_case_7day.png", p, width = 16, height = 9)