-
Notifications
You must be signed in to change notification settings - Fork 7
/
plot_data.r
84 lines (68 loc) · 2.61 KB
/
plot_data.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
75
76
77
78
79
80
81
82
83
84
library(here)
library(purrr)
library(ggplot2)
library(socialmixr)
library(dplyr)
source(here::here("scripts", "read.R"))
prev <- read_cis()
p <- ggplot(prev %>%
filter(level == "national"),
aes(x = end_date, ymin = lower, ymax = upper)) +
geom_ribbon() +
scale_x_date(breaks = "2 months", labels = date_format("%b %Y")) +
theme_minimal() +
facet_wrap(~ variable) +
xlab("")
p_natural <- p +
scale_y_continuous("Prevalence of SARS-CoV-2 positivity",
label = scales::percent_format(accuracy = 0.1))
p_log <- p +
scale_y_log10("Prevalence of SARS-CoV-2 positivity",
label = scales::percent_format(accuracy = 0.1))
ggsave(here::here("figures", "national_prevalence.pdf"), p_natural,
width = 12, height = 8)
ggsave(here::here("figures", "national_prevalence_log.pdf"), p_log,
width = 12, height = 8)
p <- ggplot(prev %>%
filter(level == "regional"),
aes(x = end_date, ymin = lower, ymax = upper)) +
geom_ribbon() +
scale_x_date(breaks = "2 months", labels = date_format("%b %Y")) +
theme_minimal() +
facet_wrap(~ variable) +
xlab("")
p_natural <- p +
scale_y_continuous("Prevalence of SARS-CoV-2 positivity",
label = scales::percent_format(accuracy = 0.1))
p_log <- p +
scale_y_log10("Prevalence of SARS-CoV-2 positivity",
label = scales::percent_format(accuracy = 0.1))
ggsave(here::here("figures", "regional_prevalence.pdf"), p_natural,
width = 16, height = 12)
ggsave(here::here("figures", "regional_prevalence_log.pdf"), p_log,
width = 16, height = 12)
age <- prev %>%
filter(level == "age_school") %>%
mutate(variable =
factor(variable, levels = c("2-10", "11-15", "16-24", "25-34",
"35-49", "50-69", "70+")))
p <- ggplot(age,
aes(x = end_date, ymin = lower, ymax = upper,
colour = variable, fill = variable)) +
geom_ribbon(alpha = 0.5) +
scale_x_date(breaks = "2 months", labels = date_format("%b %Y")) +
scale_colour_brewer("Age", palette = "Set1") +
scale_fill_brewer("Age", palette = "Set1") +
theme_minimal() +
ggtitle("England") +
xlab("")
p_natural <- p +
scale_y_continuous("Prevalence of SARS-CoV-2 positivity",
label = scales::percent_format(accuracy = 0.1))
p_log <- p +
scale_y_log10("Prevalence of SARS-CoV-2 positivity",
label = scales::percent_format(accuracy = 0.1))
ggsave(here::here("figures", "age_prevalence.pdf"), p_natural,
width = 12, height = 8)
ggsave(here::here("figures", "age_prevalence_log.pdf"), p_log,
width = 12, height = 8)