## # Endriss & Vahsen et al. density-dependent dispersal analyses ## # Figure 5 - Interaction panel plot (dispden:habitat and dispden:momden). # Extracted lsmeans from supplemental analysis. # Created by MLV 29 May 2018 # Updated by SBE 31 August 2018 # Clear object memory rm(list=ls()) # ------------------------------ # # Note: Need to set directory or # include file path for .csv # ------------------------------ # # Read in data. indata <- read.csv("LMM_DH_DM_Means.csv") # Remove first nuisance indexing column summary <- indata[, colnames(indata) != "X"] # We have 1000 interations for each of these mean values We should probably take # the average values of the means and CIs. # Take means of means, lower CI, and upper CI from emmeans output summary <- colMeans(summary) # Separate data back into manageable form (rr [background] beetles are # specified; if no rr, then assume sf [experimental]) DH_int_means <- summary[c(5:8)] DH_int_lower <- summary[c(13:16)] DH_int_upper <- summary[c(21:24)] DM_int_means <- summary[c(29:32)] DM_int_lower <- summary[c(37:40)] DM_int_upper <- summary[c(45:48)] DH_int_means_rr <- summary[c(1:4)] DH_int_lower_rr <- summary[c(9:12)] DH_int_upper_rr <- summary[c(17:20)] DM_int_means_rr <- summary[c(25:28)] DM_int_lower_rr <- summary[c(33:36)] DM_int_upper_rr <- summary[c(41:44)] pdf("Fig5.pdf", height = 4.95, width = 8.54) # First panel = dispersal density by habitat # Plot experimental beetles first x <- c(1.2,2.2) colors <- c("plum","#e17ca5","#7a7a7a", "#3d3d3d") par(mar = c(5,5,2,0), fig = c(0, 0.527, 0, 1), cex = 1) plot(x, DH_int_means[c(1,3)], ylim = c(0,2.5), col = colors[1], pch = 16, xlim = c(0.85, 2.35), xaxt = "n", xlab = "", ylab = "", yaxt = "n", cex = 2) axis(side = 1, at = c(0,1.1,2.1,3), labels = FALSE) axis(side = 2, at = seq(-0.5,3,0.5), labels = TRUE, las = 1, tick = TRUE) # Overlay standardized beetles lines(x-0.15, DH_int_means_rr[c(1,3)], lwd = 1.2, col = colors[3], lty = 2) lines(x-0.2, DH_int_means_rr[c(2,4)], lwd = 1.2, col = colors[4]) points(x-0.15, DH_int_means_rr[c(1,3)], cex = 2, col = colors[3], pch = 16) points(x-0.2, DH_int_means_rr[c(2,4)], cex = 2, col = colors[4], pch = 16) arrows(x-0.15, DH_int_lower_rr[c(1,3)], x-0.15, DH_int_upper_rr[c(1,3)], col = colors[3], code = 3, angle = 90, length = 0.1,lwd = 1.5) arrows(x-0.2, DH_int_lower_rr[c(2,4)], x-0.2, DH_int_upper_rr[c(2,4)], col = colors[4], code = 3, angle = 90, length = 0.1,lwd = 1.5) points(x-0.2, DH_int_means_rr[c(2,4)], col = "white", cex = 1.5, pch = 16) points(x-0.15, DH_int_means_rr[c(1,3)], col = "white", cex = 1.5, pch = 16) # Continue with experimental beetles lines(x, DH_int_means[c(1,3)], lwd = 1.5, col = colors[1], lty = 2) points(x-0.05, DH_int_means[c(2,4)], pch = 16, col = colors[2], cex = 2) lines(x-0.05, DH_int_means[c(2,4)], lwd = 1.5, col = colors[2], lty=1) arrows(x, DH_int_lower[c(1,3)], x, DH_int_upper[c(1,3)], col = colors[1], code = 3, angle = 90, length = 0.1,lwd = 1.5) arrows(x-0.05, DH_int_lower[c(2,4)], x-0.05, DH_int_upper[c(2,4)], col = colors[2], code = 3, angle = 90, length = 0.1,lwd = 1.5) points(x-0.05, DH_int_means[c(2,4)], col = "white", cex = 1.5, pch = 16) points(x, DH_int_means[c(1,3)], col = "white", cex = 1.5, pch = 16) mtext(side = 1, at = c(1.1,2.1), c("high", "low"), padj=1) mtext(side = 1, at = 1.6, "habitat quality", padj = 3, cex=1.25) text(1.7, 2, "high current density", col = colors[4], srt = -.5) text(1.6, 1, "low current density", col = colors[3], srt = 11) text(expression('p'['D'%*%'H']== 0.084), x = 1.025, y = 0.025) text('A', font = 2, x = 0.875, y = 2.45, cex = 1.5) mtext("( and standardized individuals)", side=2, line=2.75) mtext("experimental", side=2, line=2.75, at = 0.43, col = colors[2], font = 2) mtext("mean distance dispersed", side=2, line=4, cex=1.25) # Second panel: dispersal density by juvenile density interaction par(mar = c(5,1,2,1), fig = c(0.534, 1, 0, 1), cex = 1, new = TRUE) plot(x, DM_int_means[c(3,1)], ylim = c(0,2.5), col = colors[1], pch = 16, xlim = c(0.85, 2.35), xaxt = "n", xlab = "", ylab = "", yaxt = "n", cex = 2) axis(side = 1, at = c(0,1.1,2.1,3), labels = FALSE) axis(side = 2, at = seq(-0.5,3,0.5), labels = FALSE, las = 1, tick = TRUE) mtext(side = 1, at = c(1.1,2.1), c("low", "high"), padj=1) mtext(side = 1, at = 1.6, "juvenile density", padj = 3, cex=1.25) # Overlay standardized beetles lines(x-0.15, DM_int_means_rr[c(3,1)], lwd = 1.2, col = colors[3], lty = 2) lines(x-0.2, DM_int_means_rr[c(4,2)], lwd = 1.2, col = colors[4]) points(x-0.15, DM_int_means_rr[c(3,1)], cex = 2, col = colors[3], pch = 16) points(x-0.2, DM_int_means_rr[c(4,2)], cex = 2, col = colors[4], pch = 16) arrows(x-0.15, DM_int_lower_rr[c(3,1)], x-0.15, DM_int_upper_rr[c(3,1)], col = colors[3], code = 3, angle = 90, length = 0.1,lwd = 1.5) arrows(x-0.2, DM_int_lower_rr[c(4,2)], x-0.2, DM_int_upper_rr[c(4,2)], col = colors[4], code = 3, angle = 90, length = 0.1,lwd = 1.5) points(x-0.15, DM_int_means_rr[c(3,1)], col = "white", cex = 1.5, pch = 16) points(x-0.2, DM_int_means_rr[c(4,2)], col = "white", cex = 1.5, pch = 16) # Back to experimental beetles lines(x, DM_int_means[c(3,1)], lwd = 1.2, col = colors[1], lty = 2) points(x-0.05, DM_int_means[c(4,2)], pch = 16, col = colors[2], cex = 2) lines(x-0.05, DM_int_means[c(4,2)], lwd = 1.2, col = colors[2], lty=1) arrows(x, DM_int_lower[c(3,1)], x, DM_int_upper[c(3,1)], col = colors[1], code = 3, angle = 90, length = 0.1) arrows(x-0.05, DM_int_lower[c(4,2)], x-0.05, DM_int_upper[c(4,2)], col = colors[2], code = 3, angle = 90, length = 0.1) points(x-0.05, DM_int_means[c(4,2)], col = "white", cex = 1.5, pch = 16) points(x, DM_int_means[c(3,1)], col = "white", cex = 1.5, pch = 16) text(1.6, 1.95, "high current density", srt = 9, col = colors[4]) text(1.6, 1, "low current density", srt = -7, col = colors[3]) text(expression('p'['D'%*%'J']== 0.019), x = 1.025, y = 0.025) text('B', font = 2, x = 0.875, y = 2.45, cex = 1.5) dev.off()