-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresentation_plots.R
117 lines (100 loc) · 4.71 KB
/
presentation_plots.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
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
###
# Group project Laura, Jule and Pascal
# ABM classroom size optimization experiments
# from 04/04/2023 to 30/05/2023
###
## load libraries and results
library(tidyverse)
library(ggplot2)
results_room <- readRDS("experiments/results_room_size_4to196_100sims.RDS")
results_spacing <- readRDS("experiments/results_room_spacing_0.1to1by0.1_100sim.RDS")
## data wrangling for plotting
# room variation
mean_app <- results_room$sim_store %>%
select(ends_with("mean"), day, class) %>%
gather(key = "mean_val", value = "mean_appereance", -c(day, class))
mean_sd <- results_room$sim_store %>%
select(ends_with("std"), day, class) %>%
gather(key = "std_val", value = "sd_appereance", -c(day, class))
plt_res_room <- cbind(mean_app, mean_sd %>% select(-c(day, class))) %>%
mutate("room_size" = sub("sim_(\\d+)_mean", "\\1 people", mean_val))
# spacing variation
mean_app <- results_spacing$sim_store %>%
select(ends_with("mean"), day, class) %>%
gather(key = "mean_val", value = "mean_appereance", -c(day, class))
mean_sd <- results_spacing$sim_store %>%
select(ends_with("std"), day, class) %>%
gather(key = "std_val", value = "sd_appereance", -c(day, class))
plt_res_spacing <- cbind(mean_app, mean_sd %>% select(-c(day, class))) %>%
mutate("room_spacing" = sub("sim_(\\d+(\\.\\d+)?)_mean", "spacing \\1", mean_val))
## first plot: show dynamics of model
fig1 <- plt_res_spacing %>%
filter(mean_val == "sim_0.6_mean") %>%
ggplot(mapping = aes(x = day, y = mean_appereance)) +
geom_errorbar(aes(ymin = mean_appereance - sd_appereance,
ymax = mean_appereance + sd_appereance),
width = 0.2) +
geom_ribbon(mapping = aes(x = day, ymin = mean_appereance - sd_appereance,
ymax = mean_appereance + sd_appereance),
alpha = 0.3, color = "grey") +
geom_point() +
labs(x = "day", y = expression(bar(n))) +
geom_line(linetype = "dashed", alpha = 0.5) +
scale_x_continuous(breaks = seq(0, 28, by = 7)) +
theme_bw()
## second plot: compare dynamics of spacing and room size
# A: sizes 16, 25, 49
fig2a <- plt_res_room %>%
filter(mean_val %in% paste0("sim_", c(16, 25, 49), "_mean")) %>%
ggplot(mapping = aes(x = day, y = mean_appereance, color = room_size)) +
geom_errorbar(aes(ymin = mean_appereance - sd_appereance, ymax = mean_appereance + sd_appereance),
width = 0.2, alpha = 0.3) +
geom_point() +
labs(x = "day", y = expression(bar(appereance)), color = "room size") +
geom_line(linetype = "dashed", alpha = 0.5) +
theme_bw()
# B: spacings 0.3, 0.6, 0.9
fig2b <- plt_res_spacing %>%
filter(mean_val %in% paste0("sim_", c(0.3, 0.6, 0.9), "_mean")) %>%
ggplot(mapping = aes(x = day, y = mean_appereance, color = room_spacing)) +
geom_errorbar(aes(ymin = mean_appereance - sd_appereance, ymax = mean_appereance + sd_appereance),
width = 0.2, alpha = 0.3) +
geom_point() +
labs(x = "day", y = expression(bar(appereance)), color = "room spacing") +
geom_line(linetype = "dashed", alpha = 0.5) +
theme_bw()
## figure 3: infection per area at different room spacing and room sizes
# mean per week per m^2 vs area
fig3a <- results_room$summary %>%
mutate(area = seq(2, 14, by = 1)**2 * 8) %>% # area per room * rooms
ggplot(mapping = aes(x = value, y = mean_week / area)) +
geom_errorbar(mapping = aes(ymin = mean_week / area - sd_week / area,
ymax = mean_week / area + sd_week / area),
width = 0.2) +
labs(x = "students/room", y = expression(bar(infections) / week / area)) +
geom_point() +
theme_bw()
# mean per week per person vs area
fig3b <- results_spacing$summary %>%
filter(area > 2) %>%
ggplot(mapping = aes(x = value, y = mean_week / area)) +
geom_errorbar(mapping = aes(ymin = mean_week / area - sd_week / area,
ymax = mean_week / area + sd_week / area),
width = 0.01) +
labs(x = "space between students", y = expression(bar(infections) / week / area)) +
geom_point() +
theme_bw()
# save the figures
if (!dir.exists("figures")){dir.create("figures")}
w = 30
h = 10
ggsave(filename = "figures/figure1_overall_dynamics.png",
plot = fig1, width = w, height = h, units = "cm")
ggsave(filename = "figures/figure2a_students_per_room_dynamics.png",
plot = fig2a, width = w, height = h, units = "cm")
ggsave(filename = "figures/figure2b_spacing_students_dynamics.png",
plot = fig2b, width = w, height = h, units = "cm")
ggsave(filename = "figures/figure3a_students_per_room_conclusion.png",
plot = fig3a, width = w, height = h, units = "cm")
ggsave(filename = "figures/figure3b_spacing_students_conclusion.png",
plot = fig3b, width = w, height = h, units = "cm")