-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.Figure_S4_gh.Rmd
More file actions
113 lines (95 loc) · 4.44 KB
/
11.Figure_S4_gh.Rmd
File metadata and controls
113 lines (95 loc) · 4.44 KB
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
---
title: "Switching behavior dry and wet season"
author: "Camila Calderon"
date: "2024-07-222"
output: html_document
---
## Load libraries
```{r setup, warning=FALSE, message=FALSE}
library(ggplot2)
library(patchwork)
library(ggmap)
library(tidyverse)
library(ggnewscale)
library(ggsn)
```
## Load data
```{r}
load(file="~/ownCloud/PhDLife/P.hastatus/Thesis/Paper1/BiologyLetters/data/Phyllostomus_HMMbehaviors.RData")
```
## Select bats with switching behavior in colony 1 during the dry early season 2022 and colony 2 during the wet season 2023
```{r, results=FALSE}
# select bats in Bocas march 2022 with area switching
bats <- bats_behaviors %>%
filter(tag_local_identifier=="PH_TS_046"| tag_local_identifier=="PH_TS_039")%>%
filter(ID!="PH_TS_039_2022-03-16")
bats_aj_2023 <- bats_behaviors %>%
filter(tag_local_identifier=="PHYL9" |tag_local_identifier=="PHYL27"|tag_local_identifier=="PHYL28")
# make a data frame with the locations of the colonies
colonies <- data.frame(colonies=c("lagruta", "ajcave"), location_lat=c( 9.396448,9.440312), location_long=c(-82.271541, -82.274955))
```
## Plot switching in map
```{r}
# plot using stamen map from Bocas
register_stadiamaps("3a58670b-0653-4668-bb0c-f9e5454596e7")
# create a bounding box
e <- make_bbox(location_long, location_lat, data = bats_behaviors)
# plot colony 1 switching
gruta_switching <- get_stadiamap(e, zoom = 13, maptype = "stamen_toner_lite") %>% ggmap()+
coord_sf(crs = "+proj=lonlat", expand = FALSE)+
scale_x_continuous(breaks = c(-82.50, -82.40, -82.30, -82.20))+
geom_path(aes(x=location_long, y=location_lat, color=as.factor(date)),data=bats)+
labs(color="date")+
new_scale_color()+
new_scale_fill()+
geom_point(data=colonies[colonies$colonies=="lagruta",], aes(x=location_long, y=location_lat, shape=colonies, size=5, fill=colonies, color=colonies))+
scale_shape_manual(values = c(21), guide="none")+
scale_color_manual(values = "black", guide="none")+
scale_fill_manual(values = alpha("black", 0.6), guide="none")+
theme_bw()+
annotation_scale(location = "bl", line_width = 1, height = unit(0.5, "cm"), pad_x= unit(0.5, "cm"), pad_y= unit(0.5, "cm"), text_cex = 2)+
guides(color = "none", size="none", alpha="none", fill="none")+
facet_wrap(.~tag_local_identifier, nrow=2)+
theme(legend.position="bottom")+
theme_linedraw()+
theme(legend.position="none",
axis.text.x = element_text(size = 14),
axis.text.y = element_text(size = 14),
axis.title.x = element_text(size = 24),
axis.title.y = element_text(size = 24),
strip.text = element_blank())+
xlab("Longitude")+
ylab("Latitude")
gruta_switching
# plot colony 2 switching
ajcave_switching <- get_stadiamap(e, zoom = 13, maptype = "stamen_toner_lite") %>% ggmap()+
coord_sf(crs = "+proj=lonlat", expand = FALSE)+
scale_x_continuous(breaks = c(-82.50, -82.40, -82.30, -82.20))+
geom_path(aes(x=location_long, y=location_lat, color=as.factor(date)),data=bats_aj_2023)+
labs(color="date")+
new_scale_color()+
new_scale_fill()+
geom_point(data=colonies[colonies$colonies=="ajcave",], aes(x=location_long, y=location_lat, shape=colonies, size=5, fill=colonies, color=colonies))+
scale_shape_manual(values = c(22), guide="none")+
scale_color_manual(values = "black", guide="none")+
scale_fill_manual(values = alpha("black", 0.6), guide="none")+
theme_bw()+
annotation_scale(location = "bl", line_width = 1, height = unit(0.5, "cm"), pad_x= unit(0.5, "cm"), pad_y= unit(0.5, "cm"), text_cex = 2)+
guides(color = "none", size="none", alpha="none", fill="none")+
facet_wrap(.~tag_local_identifier, nrow=3)+
theme_linedraw()+
theme(legend.position="none",
axis.text.x = element_text(size = 14),
axis.text.y = element_text(size = 14),
axis.title.x = element_text(size = 24),
axis.title.y = element_text(size = 24),
strip.text = element_blank())+
xlab("Longitude")+
ylab("Latitude")
ajcave_switching
# compile plots for figure S4
((gruta_switching | ajcave_switching) + plot_layout(axis_titles = "collect")+ plot_annotation(tag_levels = "A") &
theme(plot.tag = element_text(face = 'bold', size=24), axis.title = element_text(face = 'bold', size=24), axis.title.x = element_text(size = 24), axis.title.y=element_text(size=24), axis.text.x=element_text(size=18), axis.text.y=element_text(size=18)))
# save figure
ggsave(file="~/ownCloud/PhDLife/P.hastatus/Thesis/Paper1/BiologyLetters/figures/FigS4.pdf", width=15, height = 10, dpi=300)
```