-
Notifications
You must be signed in to change notification settings - Fork 1
/
figure_2.R
154 lines (126 loc) · 5.39 KB
/
figure_2.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
## This file creates figure 2
#################
# Libraries
library(tidyverse)
library(tidybayes)
library(RColorBrewer)
library(patchwork)
library(ggdist)
#################
# Read in data
LCC1_V <- read_csv('results/fitted_draws/LCC1_vehicle.csv') %>%
mutate(condition = 'LCC1 (SENS), VEH') %>%
mutate(treatment = 'Vehicle')
LCC1_T <- read_csv('results/fitted_draws/LCC1_treatment.csv') %>%
mutate(condition = 'LCC1 (SENS), TRT') %>%
mutate(treatment = 'Treatment')
LCC9_V <- read_csv('results/fitted_draws/LCC9_vehicle.csv') %>%
mutate(condition = 'LCC9 (RES), VEH') %>%
mutate(treatment = 'Vehicle')
LCC9_T <- read_csv('results/fitted_draws/LCC9_treatment.csv') %>%
mutate(condition = 'LCC9 (RES), TRT') %>%
mutate(treatment = 'Treatment')
df <- full_join(LCC1_V, LCC1_T) %>%
full_join(LCC9_V) %>%
full_join(LCC9_T) %>%
filter(.width == .95) %>%
mutate(treatment = as.factor(treatment)) %>%
mutate(treatment = relevel(treatment, ref = 'Vehicle'),
condition = as.factor(condition))
##
LCC1_V <- read_csv('results/parameters/LCC1_vehicle.csv') %>%
mutate(condition = 'LCC1 (SENS), VEH') %>%
mutate(treatment = 'Vehicle')
LCC1_T <- read_csv('results/parameters/LCC1_treatment.csv') %>%
mutate(condition = 'LCC1 (SENS), TRT') %>%
mutate(treatment = 'Treatment')
LCC9_V <- read_csv('results/parameters/LCC9_vehicle.csv') %>%
mutate(condition = 'LCC9 (RES), VEH') %>%
mutate(treatment = 'Vehicle')
LCC9_T <- read_csv('results/parameters/LCC9_treatment.csv') %>%
mutate(condition = 'LCC9 (RES), TRT') %>%
mutate(treatment = 'Treatment')
df.2 <- full_join(LCC1_V, LCC1_T) %>%
full_join(LCC9_V) %>%
full_join(LCC9_T) %>%
mutate(i = if_else(i == 1, 'Intrinsic growth rate (r)',
'Carrying capacity (K)'))
#################
# Panel 1
pal <- c(brewer.pal(9, 'Blues')[c(4, 7)], brewer.pal(9, 'Greens')[c(4, 7)])
df$condition <- ordered(df$condition, c('LCC1 (SENS), VEH','LCC1 (SENS), TRT', 'LCC9 (RES), VEH', 'LCC9 (RES), TRT'))
p1 <- ggplot(df, aes(x = rank, group = condition))+
geom_line(aes(y = y_rep_mean, color = condition), size = 1.25, alpha=0.75)+
geom_point(aes(y = agg_count, color = condition), size = 1.75)+
geom_ribbon(aes(ymin = .lower, ymax = .upper, group = interaction(condition, .width), fill = condition), alpha = .35, show.legend = F)+
theme_minimal()+
scale_color_manual(values = pal[c(1, 3, 2, 4)])+
scale_fill_manual(values = pal[c(1, 3, 2, 4)])+
labs(x = 'Time steps',
y = 'Cell count',
color = 'Condition',
tag = 'A')+
theme(legend.position = c(0.75, 0.85),
legend.text=element_text(size=18),
axis.text=element_text(size=20),
axis.title=element_text(size=30),
legend.title=element_text(size = 20),
strip.text.x = element_text(size = 18),
plot.tag = element_text(size = 25))+
facet_wrap(~condition)
#################
# Panel 2
df.2$i <- ordered(df.2$i, c('Intrinsic growth rate (r)', 'Carrying capacity (K)'))
df.2$condition <- ordered(df.2$condition, c('LCC1 (SENS), VEH', 'LCC1 (SENS), TRT', 'LCC9 (RES), VEH', 'LCC9 (RES), TRT'))
p2 <- df.2 %>%
filter(i == 'Intrinsic growth rate (r)') %>%
ggplot(aes(x = condition, y = theta, fill = condition))+
stat_halfeye(orientation = 'vertical',
show.legend = F,
normalize = 'xy',
.width = c(.95, .5),
aes(fill_ramp = stat(cut_cdf_qi(cdf,
.width = c(.5, .95, 1),
labels = scales::percent_format(accuracy = 1)))))+
scale_fill_ramp_discrete(range = c(.9, .3), na.translate = F)+
#facet_wrap(~i, scales = 'free_y')+
scale_x_discrete(labels = c('LCC1,\nVEH', 'LCC1,\nTRT', 'LCC9,\nVEH','LCC9,\nTRT'))+
theme_minimal()+
labs(title = 'Intrinsic growth rate (r)', x = '', y = '')+
scale_fill_manual(values = pal[c(1, 3, 2, 4)])+
labs(x = '', y = '', tag = 'B')+
theme(strip.text.x = element_text(size = 18),
axis.text.y = element_text(size = 20),
axis.text.x = element_text(size = 13),
plot.tag = element_text(size = 25),
plot.title = element_text(hjust = 0.5, size = 20))+
ylim(0.01, 0.05)
p3 <- df.2 %>%
filter(i == 'Carrying capacity (K)') %>%
ggplot(aes(x = condition, y = theta, fill = condition))+
stat_halfeye(orientation = 'vertical',
show.legend = F,
normalize = 'xy',
.width = c(.95, .5),
aes(fill_ramp = stat(cut_cdf_qi(cdf,
.width = c(.5, .95, 1),
labels = scales::percent_format(accuracy = 1)))))+
scale_fill_ramp_discrete(range = c(.9, .3), na.translate = F)+
#facet_wrap(~i, scales = 'free_y')+
scale_x_discrete(labels = c('LCC1,\nVEH', 'LCC1,\nTRT', 'LCC9,\nVEH','LCC9,\nTRT'))+
labs(title = 'Carrying capacity (K)', x = '', y = '')+
theme_minimal()+
scale_fill_manual(values = pal[c(1, 3, 2, 4)])+
theme(strip.text.x = element_text(size = 18),
axis.text.y = element_text(size = 20),
axis.text.x = element_text(size = 13),
plot.tag = element_text(size = 25),
plot.title = element_text(hjust = 0.5, size = 20))+
ylim(3500, 16000)
#################
# Save figure
design <- "
1123
1123
"
ggsave('results/images/figures/fig2.jpeg', p1 + p2 + p3 + plot_layout(design = design), scale = 1, dpi = 300, width = 15, height = 8)