get_community_synchrony
A quick check to make sure the function is working as expected.
The get_community_synchrony
function requires several other packages...
library(communitySynchrony) library(plyr) library(reshape2) library(synchrony) library(ggplot2)
I'm going to use the Kansas data as a test first, then move to the Idaho data.
site <- "Kansas" spp_list <- c("BOCU","BOHI","SCSC") num_spp <- length(spp_list) ks_data <- data.frame(quad=NA, year=NA, totCover=NA, species=NA) for(dospp in 1:num_spp){ #loop through species to read in data spp_now <- spp_list[dospp] quad_file <- paste("../../data/", site,"/",spp_now,"/quadratCover.csv",sep="") spp_data <- read.csv(quad_file) spp_data$species <- spp_now ks_data <- rbind(ks_data, spp_data) } #end species looping for raw data ks_data <- ks_data[2:nrow(ks_data),] #remove first NA row
Chengjin identified several quad-years that need to be removed due to dominance of BOCU.
tmp1<-which(ks_data$quad_data=="q25" & (ks_data$year<35 | ks_data$year>62)) tmp2<-which(ks_data$quad_data=="q27") tmp3<-which(ks_data$quad=="q28") tmp4<-which(ks_data$quad=="q30") tmp5<-which(ks_data$quad=="q31" & (ks_data$year<35 | ks_data$year>39)) tmp6<-which(ks_data$quad=="q32" & (ks_data$year<35 | ks_data$year>41)) tmp<-c(tmp1,tmp2,tmp3,tmp4,tmp5,tmp6) ks_data<-ks_data[-tmp,] # exclude the records later than 1968, to keep the same random year effect... ks_data<-subset(ks_data,year<68)
out <- get_comm_synchrony(ts_data = ks_data) str(out) names(out)
pgr_data <- out$growth_rates pgr_melt <- melt(pgr_data, id.vars = "year") ggplot(pgr_melt, aes(x=(year+1900), y=value, color=variable))+ geom_line()+ geom_point()
site <- "Idaho" spp_list <- sort(c("PSSP","HECO","POSE","ARTR")) num_spp <- length(spp_list) id_data <- data.frame(quad=NA, year=NA, totCover=NA, species=NA) for(dospp in 1:num_spp){ #loop through species to read in data spp_now <- spp_list[dospp] quad_file <- paste("../../data/", site,"/",spp_now,"/quadratCover.csv",sep="") spp_data <- read.csv(quad_file) spp_data$species <- spp_now id_data <- rbind(id_data, spp_data) } #end species looping for raw data id_data <- id_data[2:nrow(id_data),] #remove first NA row id_data <- subset(id_data, species!="ARTR") #take out the shrub out <- get_comm_synchrony(ts_data = id_data) str(out) names(out)
pgr_data <- out$growth_rates pgr_melt <- melt(pgr_data, id.vars = "year") ggplot(pgr_melt, aes(x=(year+1900), y=value, color=variable))+ geom_line()+ geom_point()
ggplot(out$percent_cover, aes(x=(year+1900), y=tot_cover, color=species))+ geom_line()+ geom_point()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.