-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_kde_fig.R
More file actions
73 lines (65 loc) · 2.4 KB
/
Copy pathplot_kde_fig.R
File metadata and controls
73 lines (65 loc) · 2.4 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
plot_kde_fig<-function(){
library(sf)
library(dplyr)
library(orsifronts)
library(ggplot2)
library(ggnewscale)
library(eks)
library(ggOceanMaps)
library(here)
library(lubridate)
#read log file for appending tag info
path<-here()
path1<-paste(path,"/data/gls_deployment_log.csv", sep="")
log<-read.csv(path1, header=TRUE)
fy<-data.frame(Tag=log$Tag, Year=log$Field_Year)
# read in the full GLS data set and filter for penguins from 2012, keeping only records that meet prior speed limits
path2<-paste(path,"/data/gls_data_ncei.csv", sep="")
gls<-read.csv(path2, stringsAsFactors = FALSE)%>%
merge(., fy, by="Tag") %>%
mutate(Month=month(as.Date(.$Date, format="%m/%d/%Y")))%>%
filter(Month%in%c(4,5))%>%
filter(Year==2012)%>%
filter(Species_Code=="ADPE" | Species_Code=="CHPE")%>%
filter(Keep==TRUE)
# add directions to the remaining tags
# this assignment is based on the mean bearing of tags during the feather growth period as determined for Hinke et al. 2015. Original code unknown.
path3<-paste(path, "/data/peng_directions.csv", sep="")
gls_directions<-read.csv(path3, header=TRUE)
dirs<-data.frame(Tag=gls_directions$Tag, Direction=gls_directions$Direction)
tt<-merge(gls, dirs, by="Tag")
tt$Spp_Dir<-paste(tt$Species_Code,tt$Direction, sep="-")
SPS<-unique(tt$Spp_Dir)
# pull out the species by direction data, make sf and transform for kernal density analysis
out<-list()
for(i in 1:3){
kdat<-tt[tt$Spp_Dir==SPS[i],]
kdat<-st_as_sf(kdat, coords=c("Longitude", "Latitude"))%>%
st_set_crs(4236)%>%
st_transform(3031)
out[[i]]<-st_kde(kdat)
}
# add ID and reformat for ggplot
adpe<-st_get_contour(out[[1]],cont=c(75))%>%
mutate(ID="Adelie")
chpe_east<-st_get_contour(out[[2]], cont=c(75))%>%
mutate(ID="Chinstrap_East")
chpe_west<-st_get_contour(out[[3]], cont=c(75))%>%
mutate(ID="Chinstrap_West")
tt<-rbind(adpe, chpe_east, chpe_west)
# prepare orsifronts
orsi<-st_as_sf(orsifronts)%>%
st_set_crs(4326)%>%
st_transform(3031)
pf<-orsi[orsi$front=="pf",]
saccf<-orsi[orsi$front=="saccf",]
#plot the map
p1<-basemap(-45, bathymetry=TRUE)+
new_scale_fill()+
geom_sf(data=tt, aes(fill=ID), alpha=0.5)+
scale_fill_manual(values=c("orange", "magenta","green"))+
guides(fill=guide_legend(override.aes=list(alpha=1)))+
geom_sf(data=pf)+
geom_sf(data=saccf)
p1
}