-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFIG_talk.R
112 lines (92 loc) · 4.38 KB
/
FIG_talk.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
library("dplyr")
library("magrittr")
library("reshape2")
library("ggplot2")
source("../R.scripts/FUNCTIONS_predator_diversity.R")
## ggplot2 theme
mytheme <- theme_bw()
phylogenetic_distance <- read.csv("../data/phylogenetic_distance.csv", stringsAsFactors = FALSE)
metabolic_occur_phylo <- read.csv("../data/metabolic_occur_phylo.csv",
stringsAsFactors = FALSE)
diet_overlap_phylo <- read.csv("../data/diet_overlap_phylo.csv",
stringsAsFactors=FALSE) %>% tbl_df()
# experimental data
pd <- read.csv("../data/pd_exp_cleaned_data.csv",
stringsAsFactors=FALSE) %>% tbl_df()
diet_predictions <- read.csv("../data/diet_predictions.csv", stringsAsFactors = FALSE)
distribution <- metabolic_occur_phylo %>%
ungroup %>%
select(phylodistance,overlap) %>%
mutate(category = "(a)", nspp = 2)
diet <- diet_overlap_phylo %>%
ungroup %>%
select(phylodistance,overlap,nspp) %>%
mutate(category = "(b)") %>%
as.data.frame
exper <- pd %>%
filter(treatment %in% c("andro","elong","tabanid","leech")) %>%
select(treatment, Culicidae:Scirtidae) %>%
group_by(treatment) %>%
summarise_each(funs(mean)) %>%
paired_predator_pianka(pred_colname = "treatment", ... = -treatment) %>%
ungroup %>%
mutate(species_pair = ifelse(species_pair == "andro_elong",
"Leptagrion.andromache_Leptagrion.elongatum", species_pair),
species_pair = ifelse(species_pair == "andro_leech",
"Leptagrion.andromache_Hirudinidae", species_pair),
species_pair = ifelse(species_pair == "andro_tabanid",
"Leptagrion.andromache_Tabanidae.spA", species_pair),
species_pair = ifelse(species_pair == "elong_leech",
"Leptagrion.elongatum_Hirudinidae", species_pair),
species_pair = ifelse(species_pair == "elong_tabanid",
"Leptagrion.elongatum_Tabanidae.spA", species_pair),
species_pair = ifelse(species_pair == "leech_tabanid",
"Tabanidae.spA_Hirudinidae", species_pair)) %>%
left_join(phylogenetic_distance) %>%
ungroup %>%
select(phylodistance,overlap,nspp) %>%
mutate(category = "(c)")
rbind(distribution) %>%
ggplot(aes(x = phylodistance, y = overlap, size = nspp)) +
geom_point(colour = "black", fill = "#00A08A",
shape = 21, alpha = 0.6) +
scale_size(range = c(3,9),name = "Number of\nprey") +
theme_minimal() +
theme(axis.ticks = element_blank(), axis.text = element_blank(),
text = element_text(size=20)) +
xlab("Phylogenetic distance") +
ylab("Similarity (Pianka's index)") +
ggsave("Distribution.png", width = 28, height = 21, units = "cm")
rbind(diet) %>%
ggplot(aes(x = phylodistance, y = overlap, size = nspp)) +
geom_point(colour = "black", fill = "#00A08A",
shape = 21, alpha = 0.6) +
scale_size(range = c(3,9),name = "Number of\nprey") +
theme_minimal() +
theme(axis.ticks = element_blank(), axis.text = element_blank(),
text = element_text(size=20)) +
xlab("Phylogenetic distance") +
ylab("Similarity (Pianka's index)") +
geom_line(aes(x = phylodistance, y = pred_m2),
size = 0.5, data = diet_predictions) +
geom_line(aes(x = phylodistance, y = upper),
size = 0.5, data = diet_predictions, linetype = "dashed") +
geom_line(aes(x = phylodistance, y = lower),
size = 0.5, data = diet_predictions, linetype = "dashed") +
mytheme + theme(strip.text = element_text(hjust = 0.01),
strip.background = element_blank())
ggsave("Diet.png", width = 28, height = 21, units = "cm")
+
facet_wrap( ~ category, scales = "free_y", nrow = 3) +
xlab("Phylogenetic distance") +
ylab("Similarity (Pianka's index)") +
scale_size(range = c(13,19),name = "Number of\nprey") +
geom_line(aes(x = phylodistance, y = pred_m2),
size = 0.5, data = diet_predictions) +
geom_line(aes(x = phylodistance, y = upper),
size = 0.5, data = diet_predictions, linetype = "dashed") +
geom_line(aes(x = phylodistance, y = lower),
size = 0.5, data = diet_predictions, linetype = "dashed") +
mytheme + theme(strip.text = element_text(hjust = 0.01),
strip.background = element_blank())
ggsave("../Figures/FIG_1.svg", height = 21, width = 28, units = "in")