-
Notifications
You must be signed in to change notification settings - Fork 1
/
03_Plot_Figs_2_3_S7.Rmd
179 lines (132 loc) · 3.96 KB
/
03_Plot_Figs_2_3_S7.Rmd
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
title: "Script to make multipanel figures 2, 3 along with figure S7"
output:
html_notebook: default
---
```{r}
install_if <- function(x) {
if(x %in% rownames(installed.packages()) == FALSE) {
message(paste(x, "is required but not installed. Installing now"))
Sys.sleep(1)
install.packages(x)
library(x)
} else{
library(x, character.only=TRUE)}
}
install_if("ggplot2")
install_if("cowplot")
install_if("here")
install_if("ggpubr")
# make a folder to export analysis data
if(! dir.exists(here("figures"))){
dir.create(here("figures"))
}
source(here("function_plotting_theme.R"))
```
# Figure 2
To produce this figure, you must run the code for Figure 2 a + inset in 1_Data_simlation.Rmd and the code for Figure 2 b in 2c_Experiment_analysis.nb.Rmd. The `Scenario` in Simulations must be set to 2 (weighted mean) and the sensitivity analysis (Analysis) must be toggled of.
load figures
```{r}
load(here("figures", "Fig_2a.RData"))
load(here("figures", "Fig_2a_i.RData"))
load(here("figures", "Fig_2b.RData"))
```
arrange figures
```{r}
Fig_2a <-
Fig_2a +
labs(x = "")+
theme_meta()+
scale_y_continuous(limits = c(-0.2,1.1))+
labs(y = "Transgressive overyielding /\n Standardized function", x = "Habitat heterogeneity")
Fig_2a_i <-
Fig_2a_i +
labs(x = "", y = "", title = "")
Fig_2a <-
Fig_2a +
annotation_custom(
ggplotGrob(Fig_2a_i),
xmin = 0.5, xmax = 5, ymin = -0.3, ymax = 0.4
)
Fig_2b <-
Fig_2b +
labs(x = "")+
scale_y_continuous(limits = c(-0.2,1.1))+
labs(y = "")+
theme_meta()
# add another figure without the BEF slope
p1 <-
ggpubr::ggarrange(Fig_2a + labs(x = "Habitat heterogeneity"),
Fig_2b + labs(x = "Habitat heterogeneity"),
ncol = 2, nrow = 1, widths = c(1, 1),
labels = c("A", "B"),
font.label =
list(size = 10,
color = "black",
face = "bold", family = NULL))
p1
ggsave(filename = here("figures", "Fig_2.pdf"),
plot = p1, width = 18, height = 9, units = "cm", dpi = 450)
```
#Figure 3
To produce this figure, you must run the code for Figure 3 a,b & in Analysis.nb.Rmd. The sensitivity analysis (Analysis) must be toggled of.
load Figures
```{r}
load(here("figures", "Fig_3A.RData"))
load(here("figures", "Fig_3B.RData"))
```
arrange Figures
```{r}
Fig_3B <-
Fig_3B+
theme_meta()+
xlab("Strain richness") +
theme(legend.position = "none")+
labs(y = "")
Legend <- cowplot::get_legend(
# create some space to the left of the legend
Fig_3A +
theme(legend.position = "bottom",
legend.box.margin = margin(0, 0, 0, 12),
legend.key=element_blank())
)
Fig_3A <-
Fig_3A+
theme_meta()+
theme(legend.position = "none")
# add the legend to the row we made earlier. Give it one-third of
# the width of one plot (via rel_widths).
Fig3 <- plot_grid(Fig_3A, Fig_3B,
align = "v",
labels="AUTO",
label_x = 0.1,
label_size = 10)
Fig3 <- plot_grid(Fig3, Legend, nrow = 2, rel_heights = c(2, .4))
Fig3
ggsave(plot = Fig3, filename = here("figures", "Fig_3.pdf"),
width = 18, height = 9, units = "cm", dpi = 450)
```
# Figure S7
note that to produce this figure you must run the code in Analysis.nb.Rmd both with and without the sensitivity analysis
load figures
```{r}
load(here("figures", "Fig_2b.RData"))
Fig_2b_with_a <-
Fig_2b+
theme_meta()+
scale_y_continuous(limits = c(0,1.1)) +
labs(y = "Transgressive overyielding /\n Standardized function", x = "Habitat heterogeneity")
load(here("figures", "Fig_S7.RData"))
Fig_2b <- Fig_2b+
theme_meta()+
scale_y_continuous(limits = c(0,1.1)) +
ylab(NULL)
```
arrange figures
```{r}
p1 <- plot_grid(Fig_2b_with_a, Fig_2b,
align = "v", labels="AUTO",
label_x = 0)
p1
ggsave(plot = p1, filename = here("figures", "Fig_S7.pdf"), width = 8, height = 4)
```