#CODE FROM HOEKSEMA FOR HIGH DPI FIGURES setwd('/Users/victoriamonette/Desktop/Data/Activity Patterns/R figures/WITH JASONS CODE') #try running this code first (but change the name of the figure file to whatever you want): jpeg("site_GJtapjag.jpeg", width = 4, height = 4, units = 'in', res = 1200) # then run your code to generate the figure here overlapPlot(GJtapir, GJjaguar, main = "Gallon Jug 2013-2016", ylim = c(0,0.15)) legend('top', c("Tapirs", "Jaguars"), lty=c(1,2), col=c(1,4), bty='n') # then run this code to finish: dev.off() #_______________________________________________ library(overlap) sitedata<- read.csv(file.choose()) setwd('/Users/victoriamonette/Desktop/Data/Activity Patterns/600dpi Figures') head(sitedata) names(sitedata) levels(sitedata$species) summary(sitedata$species) range(sitedata$time) table(sitedata$site, sitedata$species) #must convert 0-1 time values to radians: timeRad<-sitedata$time * 2 * pi #extract data for tapirs, jaguars and humans in entire region GJtapir <- timeRad[sitedata$site == 'GJ' & sitedata$species == 'Tapir'] densityPlot(GJtapir, rug=TRUE, ylim = c(0,0.18)) GJjaguar <- timeRad[sitedata$site == 'GJ' & sitedata$species == 'Jaguar'] densityPlot(GJjaguar, rug=TRUE, ylim = c(0,0.18)) GJhuman <- timeRad[sitedata$site == 'GJ' & sitedata$species == 'Human'] densityPlot(GJhuman, rug=TRUE, ylim = c(0,0.18)) #calculate overlap of tapirs and jaguars using Dhat4 (bc lowest sample size is = 202) min(length(GJtapir), length(GJjaguar)) estGJtapjag <- overlapEst(GJtapir, GJjaguar, type="Dhat4") estGJtapjag estGJtapjag_1 <- overlapEst(GJtapir, GJjaguar, type="Dhat1") estGJtapjag_1 par(mfrow=c(4,2)) #plot the curves jpeg("All years_GJtapjag_labels.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(GJtapir, GJjaguar, main = "Gallon Jug 2013-2016", ylim = c(0,0.15), width = 3, height = 2.5, units = 'in', res=600) legend('top', c("Tapirs", "Jaguars"), lty=c(1,2), col=c(1,4), bty='n') dev.off() #can position legend as 'bottomright', 'bottom', 'bottomleft', 'left', #topleft, top, topright, right, or center #plot without title and axes labels, x-axis = 0.15 max jpeg("All years_GJtapjag.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(GJtapir, GJjaguar, main = "", cex.axis = 1.5, ylim = c(0,0.15), ylab = "", xlab = "", res = 600) dev.off() #calculate overlap of tapirs and humans using Dhat4 (bc lowest sample size is = 202) min(length(GJtapir), length(GJhuman)) estGJtaphum <- overlapEst(GJtapir, GJhuman, type="Dhat4") estGJtaphum estGJtaphum_1 <- overlapEst(GJtapir, GJhuman, type="Dhat1") estGJtaphum_1 #plot the curves jpeg("All years_GJtaphum_labels.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(GJtapir, GJhuman, main = "Gallon Jug 2013-2016", ylim = c(0,0.18)) legend('top', c("Tapirs", "Humans"), lty=c(1,2), col=c(1,4), bty='n') dev.off() #plot without title and axes labels, x-axis = 0.15 max jpeg("All years_GJtaphum.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(GJtapir, GJhuman, main = "", cex.axis = 1.5, ylim = c(0,0.15), ylab = "", xlab = "", res = 600) dev.off() #generate 10,000 smoothed bootstrap samples for tapirs, jaguars & humans in GJ bootGJtapir<- resample(GJtapir, 10000) dim(bootGJtapir) bootGJjaguar<- resample(GJjaguar, 10000) dim(bootGJjaguar) bootGJhuman<- resample(GJhuman, 10000) dim(bootGJhuman) #generate overlap estimates from each pair of samples GJtapjag<- bootEst(bootGJtapir, bootGJjaguar, type = "Dhat4", cores = NA) (GJtapjagBSmean <- mean(GJtapjag)) #means take a while GJtaphum<- bootEst(bootGJtapir, bootGJhuman, type = "Dhat4", cores = NA) (GJtaphumBSmean <- mean(GJtaphum)) #extract confidence intervals bootCI(estGJtapjag, GJtapjag) bootCI(estGJtaphum, GJtaphum) #if CI values are outside of 0-1 range, carry out the corrections on a log scale and back transform bootCIlogit(estGJtapjag, GJtapjag) bootCIlogit(estGJtaphum, GJtaphum) #_______HILLBANK 2013-2016 POOLED_____ library(overlap) sitedata<- read.csv(file.choose()) head(sitedata) names(sitedata) levels(sitedata$species) summary(sitedata$species) range(sitedata$time) table(sitedata$site, sitedata$species) #must convert 0-1 time values to radians: timeRad<-sitedata$time * 2 * pi #extract data for tapirs, jaguars and humans in entire region HBtapir <- timeRad[sitedata$site == 'HB' & sitedata$species == 'Tapir'] densityPlot(HBtapir, rug=TRUE, ylim = c(0,0.18)) HBjaguar <- timeRad[sitedata$site == 'HB' & sitedata$species == 'Jaguar'] densityPlot(HBjaguar, rug=TRUE, ylim = c(0,0.18)) HBhuman <- timeRad[sitedata$site == 'HB' & sitedata$species == 'Human'] densityPlot(HBhuman, rug=TRUE, ylim = c(0,0.18)) #calculate overlap of tapirs and jaguars using Dhat4 (bc lowest sample size is = 241) min(length(HBtapir), length(HBjaguar)) estHBtapjag <- overlapEst(HBtapir, HBjaguar, type="Dhat4") estHBtapjag estHBtapjag_1 <- overlapEst(HBtapir, HBjaguar, type="Dhat1") estHBtapjag_1 #plot the curves jpeg("All years_HBtapjag_labels.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(HBtapir, HBjaguar, main = "Hillbank 2013-2016", ylim = c(0,0.15)) legend('top', c("Tapirs", "Jaguars"), lty=c(1,2), col=c(1,4), bty='n') dev.off() #can position legend as 'bottomright', 'bottom', 'bottomleft', 'left', #topleft, top, topright, right, or center #plot without title and axes labels, x-axis = 0.15 max jpeg("All years_HBtapjag.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(HBtapir, HBjaguar, main = "", cex.axis = 1.5, ylim = c(0,0.15), ylab = "", xlab = "", res = 600) dev.off() #calculate overlap of tapirs and humans using Dhat4 (bc lowest sample size is = 224) min(length(HBtapir), length(HBhuman)) estHBtaphum <- overlapEst(HBtapir, HBhuman, type="Dhat4") estHBtaphum estHBtaphum_1 <- overlapEst(HBtapir, HBhuman, type="Dhat1") estHBtaphum_1 #plot the curves jpeg("All years_HBtaphum_labels.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(HBtapir, HBhuman, main = "Hillbank 2013-2016", ylim = c(0,0.15)) legend('top', c("Tapirs", "Humans"), lty=c(1,2), col=c(1,4), bty='n') dev.off() #plot without title and axes labels, x-axis = 0.15 max jpeg("All years_HBtaphum.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(HBtapir, HBhuman, main = "", cex.axis = 1.5, ylim = c(0,0.15), ylab = "", xlab = "", res = 600) dev.off() #generate 10,000 smoothed bootstrap samples for tapirs, jaguars & humans in HB bootHBtapir<- resample(HBtapir, 10000) dim(bootHBtapir) bootHBjaguar<- resample(HBjaguar, 10000) dim(bootHBjaguar) bootHBhuman<- resample(HBhuman, 10000) dim(bootHBhuman) #generate overlap estimates from each pair of samples HBtapjag<- bootEst(bootHBtapir, bootHBjaguar, type = "Dhat4", cores = NA) (HBtapjagBSmean <- mean(HBtapjag)) #means take a while HBtaphum<- bootEst(bootHBtapir, bootHBhuman, type = "Dhat4", cores = NA) (HBtaphumBSmean <- mean(HBtaphum)) #extract confidence intervals bootCI(estHBtapjag, HBtapjag) bootCI(estHBtaphum, HBtaphum) #if CI values are outside of 0-1 range, carry out the corrections on a log scale and back transform bootCIlogit(estHBtapjag, HBtapjag) bootCIlogit(estHBtaphum, HBtaphum) #______LA MILPA 2013-2016 POOLED______ library(overlap) sitedata<- read.csv(file.choose()) head(sitedata) names(sitedata) levels(sitedata$species) summary(sitedata$species) range(sitedata$time) table(sitedata$site, sitedata$species) #must convert 0-1 time values to radians: timeRad<-sitedata$time * 2 * pi #extract data for tapirs, jaguars and humans in entire region LMtapir <- timeRad[sitedata$site == 'LM' & sitedata$species == 'Tapir'] densityPlot(LMtapir, rug=TRUE, ylim = c(0,0.18)) LMjaguar <- timeRad[sitedata$site == 'LM' & sitedata$species == 'Jaguar'] densityPlot(LMjaguar, rug=TRUE, ylim = c(0,0.18)) LMhuman <- timeRad[sitedata$site == 'LM' & sitedata$species == 'Human'] densityPlot(LMhuman, rug=TRUE, ylim = c(0,0.18)) #calculate overlap of tapirs and jaguars using Dhat1 (bc lowest sample size is = 42) min(length(LMtapir), length(LMjaguar)) estLMtapjag <- overlapEst(LMtapir, LMjaguar, type="Dhat1") estLMtapjag estLMtapjag_4 <- overlapEst(LMtapir, LMjaguar, type="Dhat4") estLMtapjag_4 #plot the curves jpeg("All years_LMtapjag_labels.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(LMtapir, LMjaguar, main = "La Milpa 2013-2016", ylim = c(0,0.15)) legend('top', c("Tapirs", "Jaguars"), lty=c(1,2), col=c(1,4), bty='n') dev.off() #can position legend as 'bottomright', 'bottom', 'bottomleft', 'left', #topleft, top, topright, right, or center #plot without title and axes labels, x-axis = 0.15 max jpeg("All years_LMtapjag.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(LMtapir, LMjaguar, main = "", cex.axis = 1.5, ylim = c(0,0.15), ylab = "", xlab = "", res = 600) dev.off() #calculate overlap of tapirs and humans using Dhat1 (bc lowest sample size is = 42) min(length(LMtapir), length(LMhuman)) estLMtaphum <- overlapEst(LMtapir, LMhuman, type="Dhat1") estLMtaphum estLMtaphum_4 <- overlapEst(LMtapir, LMhuman, type="Dhat4") estLMtaphum_4 #plot the curves jpeg("All years_LMtaphum_labels.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(LMtapir, LMhuman, main = "La Milpa 2013-2016", ylim = c(0,0.15)) legend('top', c("Tapirs", "Humans"), lty=c(1,2), col=c(1,4), bty='n') dev.off() #plot without title and axes labels, x-axis = 0.15 max jpeg("All years_LMtaphum.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(LMtapir, LMhuman, main = "", cex.axis = 1.5, ylim = c(0,0.15), ylab = "", xlab = "", res = 600) dev.off() #generate 10,000 smoothed bootstrap samples for tapirs, jaguars & humans in LM bootLMtapir<- resample(LMtapir, 10000) dim(bootLMtapir) bootLMjaguar<- resample(LMjaguar, 10000) dim(bootLMjaguar) bootLMhuman<- resample(LMhuman, 10000) dim(bootLMhuman) #generate overlap estimates from each pair of samples LMtapjag<- bootEst(bootLMtapir, bootLMjaguar, type = "Dhat4", cores = NA) (LMtapjagBSmean <- mean(LMtapjag)) #means take a while LMtaphum<- bootEst(bootLMtapir, bootLMhuman, type = "Dhat4", cores = NA) (LMtaphumBSmean <- mean(LMtaphum)) #extract confidence intervals bootCI(estLMtapjag, LMtapjag) bootCI(estLMtaphum, LMtaphum) #if CI values are outside of 0-1 range, carry out the corrections on a log scale and back transform bootCIlogit(estLMtapjag, LMtapjag) bootCIlogit(estLMtaphum, LMtaphum) #______YALBAC 2014-2016 POOLED_______ #extract data for tapirs, jaguars and humans in entire region YBtapir <- timeRad[sitedata$site == 'YB' & sitedata$species == 'Tapir'] densityPlot(YBtapir, rug=TRUE, ylim = c(0,0.18)) YBjaguar <- timeRad[sitedata$site == 'YB' & sitedata$species == 'Jaguar'] densityPlot(YBjaguar, rug=TRUE, ylim = c(0,0.18)) YBhuman <- timeRad[sitedata$site == 'YB' & sitedata$species == 'Human'] densityPlot(YBhuman, rug=TRUE, ylim = c(0,0.18)) #calculate overlap of tapirs and jaguars using Dhat4 (bc lowest sample size is = 111) min(length(YBtapir), length(YBjaguar)) estYBtapjag <- overlapEst(YBtapir, YBjaguar, type="Dhat4") estYBtapjag estYBtapjag_1 <- overlapEst(YBtapir, YBjaguar, type="Dhat1") estYBtapjag_1 #plot the curves jpeg("All years_YBtapjag_labels.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(YBtapir, YBjaguar, main = "Yalbac 2014-2016", ylim = c(0,0.15)) legend('top', c("Tapirs", "Jaguars"), lty=c(1,2), col=c(1,4), bty='n') dev.off() #can position legend as 'bottomright', 'bottom', 'bottomleft', 'left', #topleft, top, topright, right, or center #plot without title and axes labels, x-axis = 0.15 max jpeg("All years_YBtapjag.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(YBtapir, YBjaguar, main = "", cex.axis = 1.5, ylim = c(0,0.15), ylab = "", xlab = "") dev.off() #to increase font size 150%:cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5 overlapPlot(YBtapir, YBjaguar, main = "", cex.axis = 1.5, ylim = c(0,0.15), ylab = "", xlab = "", res = 600) #calculate overlap of tapirs and humans using Dhat4 (bc lowest sample size is = 111) min(length(YBtapir), length(YBhuman)) estYBtaphum <- overlapEst(YBtapir, YBhuman, type="Dhat4") estYBtaphum estYBtaphum_1 <- overlapEst(YBtapir, YBhuman, type="Dhat1") estYBtaphum_1 #plot the curves jpeg("All years_YBtaphum_labels.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(YBtapir, YBhuman, main = "Yalbac 2014-2016", ylim = c(0,0.18)) legend('top', c("Tapirs", "Humans"), lty=c(1,2), col=c(1,4), bty='n') dev.off() #plot without title and axes labels, x-axis = 0.15 max jpeg("All years_YBtaphum.jpeg", width = 5, height = 4.5, units = 'in', res = 600) overlapPlot(YBtapir, YBhuman, main = "", cex.axis = 1.5, ylim = c(0,0.15), ylab = "", xlab = "", res = 600) dev.off() #generate 10,000 smoothed bootstrap samples for tapirs, jaguars & humans in YB bootYBtapir<- resample(YBtapir, 10000) dim(bootYBtapir) bootYBjaguar<- resample(YBjaguar, 10000) dim(bootYBjaguar) bootYBhuman<- resample(YBhuman, 10000) dim(bootYBhuman) #generate overlap estimates from each pair of samples YBtapjag<- bootEst(bootYBtapir, bootYBjaguar, type = "Dhat4", cores = NA) (YBtapjagBSmean <- mean(YBtapjag)) #means take a while YBtaphum<- bootEst(bootYBtapir, bootYBhuman, type = "Dhat4", cores = NA) (YBtaphumBSmean <- mean(YBtaphum)) #extract confidence intervals bootCI(estYBtapjag, YBtapjag) bootCI(estYBtaphum, YBtaphum) #if CI values are outside of 0-1 range, carry out the corrections on a log scale and back transform bootCIlogit(estYBtapjag, YBtapjag) bootCIlogit(estYBtaphum, YBtaphum)