-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualize.R
74 lines (66 loc) · 1.84 KB
/
visualize.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
68
69
70
71
72
73
74
suppressPackageStartupMessages({
require(data.table)
require(ggplot2)
})
.debug <- "FRA"
.args <- if (interactive()) sprintf(c(
"results/%s/result.rds", "fig/%s.png"
), .debug) else commandArgs(trailingOnly = TRUE)
#' @example
#' .args <- gsub("ESP", "USA", .args)
rawpth <- .args[1]
targetfig <- tail(.args, 1)
ref <- readRDS(rawpth)
# TODO: consider if worth adding:
# - from peaks, draw post-wave threshold until reached / new peak
# - once post wave threshold reached, draw new wave threshold until reached
# TODO: area plot version for shaded regions
p <- ggplot(ref) +
aes(date, new_cases_smoothed_per_million) +
geom_bar(
aes(fill = range_annotation, color = NULL),
#data = function(dt) dt[!is.na(range_annotation)],
alpha = 0.5, width = 1, stat = "identity"
) +
# geom_line(aes(y=zz, color = "zigzag")) +
geom_line(color = "black") +
geom_point(
aes(shape = point_annotation)#,
#data = function(dt) dt[point_annotation %in% c("peak", "uptick")]
) +
scale_x_date(
"Date",
date_breaks = "months",
#date_minor_breaks = "2 weeks",
date_labels = "%b"
) +
scale_y_continuous("reported 7-day mean case incidence per 1M") +
scale_shape_manual(
"Point Indicators",
breaks = levels(ref$point_annotation),
values = c(peak=17, uptick=23),
drop = FALSE
) +
scale_fill_manual(
"Range Indicators",
breaks = levels(ref$range_annotation),
labels = c(
above = "above 33%",
below = "below 15%",
post = "between 15% & 33%, not upswing",
upswing = "upswing"
),
values = c(
above = "firebrick",
upswing = "orange",
below = "dodgerblue",
post = "yellow"
),
drop = F
) +
theme_minimal() +
theme(
legend.position = c(0, 1),
legend.justification = c(0, 1)
)
ggsave(targetfig, p, height = 3.5, width = 7, units = "in")