knitr::opts_chunk$set(echo = TRUE)
Clean and tidy data taken from leaf litter 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-leaf-litter", "CSV_leaf_litter_both_sites", "leaf_litter_insects_CSV.csv")
litter <- read.csv(file= file., skip = 6, header = TRUE, blank.lines.skip = TRUE, na.strings = "")
explore <- TRUE if(explore == TRUE){ head(litter) summary(litter,15) dim(litter) }
litter <- na.omit(litter)
names(litter) <- gsub("^X","S",names(litter))
head(litter)
site month taxa S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12 S13 S14 S15 S16 S17 S18
1 Broadleaf Jan Spiders 0 0 0 2 3 2 1 1 0 1 2 1 6 1 0 2 0 0 2 Broadleaf Jan Ants 0 0 0 4 1 1 3 0 0 0 1 0 5 0 0 0 0 0 3 Broadleaf Jan Cockroach 0 1 0 0 1 2 1 0 0 2 1 0 5 1 0 0 0 1 4 Broadleaf Jan Beetle 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 5 Broadleaf Jan Cricket 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 Broadleaf Jan Gusano 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0
Melt data from wide to long.
id.vars. <- names(litter)[-grep("^S",names(litter))] litter.melt <- melt(data = litter, id.vars = id.vars., variable.name = "sample", value.name = "N")
summary(factor(litter.melt$sample))
litter.melt$sample <- gsub("S","",litter.melt$sample ) summary(factor(litter.melt$sample)) litter.melt$sample <- as.numeric(litter.melt$sample)
explore <- TRUE wrking <- litter.melt if(explore == TRUE){ head(wrking) summary(wrking,15) dim(wrking) }
litter.melt$site <- factor(litter.melt$site, levels = c("La Cueva","La Caoba","Morelia","El Corral", "Broadleaf"))
ggplot(data = litter.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 = litter.melt, aes(y = N, x = site, color = site)) + stat_summary(fun.data = "mean_cl_boot",size = 2)
library(ggpubr) ggerrorplot(data = litter.melt, y = "N", x = "site", color = "site", desc_stat = "mean_ci", size = 2)
litter <- litter.melt save(litter, file = "./data/litter.RData")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.