library(ggplot2)
rm(list=ls())
Import processed dataframes from Overlap scripts
df15<-read.csv("Processed Data/overlap df from 2015 overlap script/overlap15.df.csv")
df16<-read.csv("Processed Data/overlap df from 2016 overlap script/overlap16.df.csv")
Subset necessary columns
df15<-df15[,c(1,2,4,11,15)]
df16<-df16[,c(1,2,4,11,15)]
Before merging the data from the two years together, some manipulation of the area values are necessary. The areas of overlap had different orders in the two years: 2015: 1) Waubun WMA, 2) Red Lake Reservation, 3) Aggasiz NWR; 2016: 1) Waubun WMA, 2) Pembina WMA, 3) Red Lake Reservation, 4) Aggasiz NWR; I'll change 2016 to: 1) Waubun WMA, 2) Red Lake Reservation, 3) Aggasiz NWR, 4) Pembina WMA
waub<-df16[df16$area==1,]
pem<-df16[df16$area==2,]
red<-df16[df16$area==3,]
ag<-df16[df16$area==4,]
pem$area="4"
red$area="2"
ag$area="3"
df16<-rbind(waub, red, ag, pem) #now should be fixed
dat<-rbind(df15, df16)
Rename area values from numbers to the names of the areas
waub<-dat[dat$area==1,]
pem<-dat[dat$area==4,]
red<-dat[dat$area==2,]
ag<-dat[dat$area==3,]
waub$area="Waubun WMA"
red$area="Red Lake Reservation"
pem$area="Pembina WMA"
ag$area="Aggasiz NWR"
dat<-rbind(waub, red, pem, ag)
dat$area<-factor(dat$area, levels = c("Red Lake Reservation", "Aggasiz NWR",
"Pembina WMA", "Waubun WMA"))
Initial plot
p<-ggplot(data=dat, aes(x=day, y=id, colour=pop))+geom_line(size=1.5)+xlim(213,275)+
facet_grid(area~., scales='free')+labs(col="Population")
p #A bit too jumbled with all the id names for each crane
In order to highlight the date range for the hunting season, colored rectangles can be added to the plot.
rects<-data.frame(xstart=258, xend=275, col="brown")
Now the plot with hunting data-range highlighted and ID labels for cranes removed. Note that this combines both years of data. It's also possible to have the data for each year separately and to stack each year next to each other. This website has useful code for doing such a thing: https://www.jaredlander.com/2013/02/vertical-dodging-in-ggplot2/ I chose not to because having twice as many lines makes the plot a lot more busy, while showing a similar trend in crane space use.
p+geom_rect(data=rects, aes(xmin=xstart, xmax=xend, ymin=-Inf, ymax=Inf, fill="Hunting Season")
,alpha=0.4, inherit.aes = FALSE)+ggtitle("Fall Staging Overlap, August 1-October 1, 2015 and 2016")+
ylab("Crane ID")+xlab("Julian Date")+scale_fill_manual(values=("#E69F00"), name="")+
theme(plot.title = element_text(hjust = 0.5))+
theme(axis.title.y=element_blank(), axis.text.y=element_blank())
Session Info
devtools::session_info()
## Session info -------------------------------------------------------------
## setting value
## version R version 3.4.0 (2017-04-21)
## system x86_64, mingw32
## ui RStudio (1.0.143)
## language (EN)
## collate English_United States.1252
## tz America/Denver
## date 2017-06-11
## Packages -----------------------------------------------------------------
## package * version date source
## base * 3.4.0 2017-04-21 local
## colorspace 1.3-2 2016-12-14 CRAN (R 3.4.0)
## compiler 3.4.0 2017-04-21 local
## datasets * 3.4.0 2017-04-21 local
## devtools 1.13.1 2017-05-13 CRAN (R 3.4.0)
## digest 0.6.12 2017-01-27 CRAN (R 3.4.0)
## evaluate 0.10 2016-10-11 CRAN (R 3.4.0)
## ezknitr 0.6 2016-09-16 CRAN (R 3.4.0)
## ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.4.0)
## graphics * 3.4.0 2017-04-21 local
## grDevices * 3.4.0 2017-04-21 local
## grid 3.4.0 2017-04-21 local
## gtable 0.2.0 2016-02-26 CRAN (R 3.4.0)
## highr 0.6 2016-05-09 CRAN (R 3.4.0)
## knitr 1.15.1 2016-11-22 CRAN (R 3.4.0)
## labeling 0.3 2014-08-23 CRAN (R 3.4.0)
## lazyeval 0.2.0 2016-06-12 CRAN (R 3.4.0)
## magrittr 1.5 2014-11-22 CRAN (R 3.4.0)
## memoise 1.1.0 2017-04-21 CRAN (R 3.4.0)
## methods * 3.4.0 2017-04-21 local
## munsell 0.4.3 2016-02-13 CRAN (R 3.4.0)
## plyr 1.8.4 2016-06-08 CRAN (R 3.4.0)
## R.methodsS3 1.7.1 2016-02-16 CRAN (R 3.4.0)
## R.oo 1.21.0 2016-11-01 CRAN (R 3.4.0)
## R.utils 2.5.0 2016-11-07 CRAN (R 3.4.0)
## Rcpp 0.12.10 2017-03-19 CRAN (R 3.4.0)
## reshape2 1.4.2 2016-10-22 CRAN (R 3.4.0)
## scales 0.4.1 2016-11-09 CRAN (R 3.4.0)
## stats * 3.4.0 2017-04-21 local
## stringi 1.1.5 2017-04-07 CRAN (R 3.4.0)
## stringr 1.2.0 2017-02-18 CRAN (R 3.4.0)
## tibble 1.3.0 2017-04-01 CRAN (R 3.4.0)
## tools 3.4.0 2017-04-21 local
## utils * 3.4.0 2017-04-21 local
## withr 1.0.2 2016-06-20 CRAN (R 3.4.0)
spun with: ezknitr::ezspin(“Event Chart Script/Event Chart.R”, out_dir=“output”)