knitr::opts_chunk$set(echo = TRUE)
Clean and tidy data taken from leaf flying samples.
library(here) library(reshape2) library(stringr) library(vegan) library(mvabund) library(ggplot2) library(cowplot) library(lme4) library(blme) library(coefplot) library("rptR")
file. <- here::here("data-raw", "data-raw-insects", "data-raw-sticky-traps", "CSV_sticky_traps_both_sites", "CSV_stick_traps_both_sites.csv")
flying <- read.csv(file= file., skip = 6, header = TRUE, blank.lines.skip = TRUE, na.strings = c("","NA"))
explore <- TRUE if(explore == TRUE){ head(flying) summary(flying,15) dim(flying) }
names(flying) <- gsub("^X","S",names(flying))
head(flying)
site taxa S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12
1 Broadleaf Coleoptera 1.0 0.5 3.5 0.0 2.0 1.5 8.0 0.0 0.0 4.5 1.5 31 2 Broadleaf Diptera 4.0 5.5 15.0 5.5 9.5 13.5 12.0 14.0 22.5 10.5 19 22 3 Broadleaf Homoptera 37.0 5.5 7.5 7.0 17.5 22.5 22.5 12.0 29.5 18.0 6.5 11 4 Broadleaf Hymenoptera 2.5 1.0 3.0 0.5 0.0 4.5 6.0 2.5 3.5 2.5 4 8 5 Broadleaf Lepidoptera 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 6 Broadleaf Spiders 0.0 0.5 0.0 0.0 0.5 0.0 0.0 0.0 0.5 0.0 0 0.5
Melt data from wide to long.
id.vars. <- names(flying)[-grep("^S",names(flying))] flying.melt <- melt(data = flying[,], id.vars = id.vars., variable.name = "sample", value.name = "N",factorsAsStrings = TRUE) summary(flying.melt)
summary(factor(flying.melt$sample))
flying.melt$sample <- gsub("S","",flying.melt$sample ) summary(factor(flying.melt$sample)) flying.melt$sample <- as.numeric(flying.melt$sample)
explore <- TRUE wrking <- flying.melt if(explore == TRUE){ head(wrking) summary(wrking,15) dim(wrking) }
flying.melt$site <- factor(flying.melt$site, levels = c("La Cueva","La Caoba","Morelia","El Corral", "Broadleaf"))
ggplot(data = flying.melt, aes(y = N, x = site, color = site)) + geom_boxplot() + facet_wrap(~ taxa,scale = "free")
#ggplot2 time saver: calculate mean SE/CIs on the fly ggplot(data = flying.melt, aes(y = N, x = site, color = site)) + stat_summary(fun.data = "mean_cl_boot",size = 2)
library(ggpubr) ggerrorplot(data = flying.melt, y = "N", x = "site", color = "site", desc_stat = "mean_ci", size = 2)
flying <- flying.melt save(flying, file = "./data/flying.RData")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.