######## Ren et al. 2024 ######## Effects of manipulated rainfall and intraspecific variation within dominant species on community assembly: insights from a long-term grassland restoration experiment # Loading necessary packages library(car) library(cati) library(dplyr) library(emmeans) library(ggbiplot) library(ggplot2) library(ggpubr) library(hypervolume) library(lattice) library(lme4) library(lmerTest) library(lsmeans) library(MASS) library(multcomp) library(multcompView) library(paran) library(rasterVis) library(vegan) ######## Data imput eco1=read.csv ("TVD_env.csv", header=T,row.names=1) toMatch <- c('DRY','MESIC','WET') eco1 <- filter(eco1, grepl(paste(toMatch, collapse="|"), eco1$ecotype)) toMatch <- c('2012','2014','2018','2019') # year which have rainout treatment eco <- filter(eco1, grepl(paste(toMatch, collapse="|"), eco1$stage)) eco[,c("ecotype","block","stage","treatment","plot")] <- lapply(eco[,c("ecotype","block","stage","treatment","plot")], factor) ecotype <- eco$ecotype block <- eco$block stage <- eco$stage treatment <- eco$treatment plot <- eco$plot Richness <- eco$Richness PDsesmpd <- eco$PDsesmpd FDsesmpd <- eco$FDsesmpd ######## Hypothesis 1: GLMM & LMM modeling # taxonomic diversity richs<-glmer(Richness ~ ecotype*stage*treatment + (1|plot:block), data=eco,family = poisson(link = "log"), control=glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e5))) Anova(richs) marginal = lsmeans(richs, ~ ecotype:stage) # multiple comparison CLD.TD = cld(marginal, alpha=0.05, reversed = T, type = "response", Letters=letters, adjust="tukey") CLD.TD # phylogenetic diversity pds<-lmer(PDsesmpd~ ecotype*stage*treatment + (1|plot:block), data=eco, REML=T, control=lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 1e5))) Anova(pds,test.statistic = 'F') marginal = lsmeans(pds, ~ ecotype:stage) CLD.PD = cld(marginal, alpha=0.05, reversed = T, type = "response", Letters=letters, adjust="tukey") CLD.PD #FD fds<-lmer(FDsesmpd~ ecotype*stage*treatment + (1|plot:block), data=eco, REML=T, control=lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 1e5))) Anova(fds,test.statistic = 'F') marginal = lsmeans(fds, ~ ecotype:stage) CLD.FD = cld(marginal, alpha=0.05, reversed = T, type = "response", Letters=letters, adjust="tukey") CLD.FD # Graphs on ecotype X year interaction erico <- eco %>% # richness summary group_by(stage, ecotype) %>% summarise( richness = mean(Richness), se1 = sd(Richness) / sqrt(n()) ) erico2 <- eco %>% # PD summary group_by(stage, ecotype) %>% summarise( pdsesmpd = mean(PDsesmpd), se2 = sd(PDsesmpd) / sqrt(n()) ) erico3 <- eco %>% # FD summary group_by(stage, ecotype) %>% summarise( fdsesmpd = mean(FDsesmpd), se3 = sd(FDsesmpd) / sqrt(n()) ) # richness graph p <- ggplot(erico, aes(stage, richness, color = ecotype, shape = ecotype)) + geom_errorbar( aes(ymin = richness-se1, ymax = richness+se1), position = position_dodge(0.3), width = 0.3)+ labs(y="Richness") + geom_point(aes(size=I(3)), position = position_dodge(0.3)) + theme_classic() + geom_line(aes(x = stage, y = richness, color = ecotype,group = ecotype), position = position_dodge(0.3),linetype = "dashed", alpha = 0.6) + scale_colour_manual(values = c("red4","darkgreen","navy"), name = "ecotype", labels = c("DRY","MESIC", "WET")) + theme(legend.position = "right",axis.title.x=element_blank(), axis.text.x=element_blank(),axis.ticks.x=element_blank(), text = element_text(size = 13)) + xlab("Year") + ylab("Richness") # PD graph q <- ggplot(erico2, aes(stage, pdsesmpd, color = ecotype, shape = ecotype)) + geom_errorbar( aes(ymin = pdsesmpd-se2, ymax = pdsesmpd+se2), position = position_dodge(0.3), width = 0.3) + geom_point(aes(size=I(3)), position = position_dodge(0.3)) + theme_classic() + geom_line(aes(x = stage, y = pdsesmpd, color = ecotype,group = ecotype), position = position_dodge(0.3),linetype = "dashed", alpha = 0.6) + geom_hline(yintercept=0, linetype="dotted", color = "grey",size=0.8, alpha = 0.5) + scale_colour_manual(values = c("red4","darkgreen","navy"), name = "ecotype", labels = c("DRY","MESIC", "WET")) + theme(legend.position = "none",axis.title.x=element_blank(), axis.text.x=element_blank(),axis.ticks.x=element_blank(), text = element_text(size = 13)) + xlab("Year") + ylab(bquote(PD[sesmpd])) # FD graph r <- ggplot(erico3, aes(stage, fdsesmpd,color = ecotype, shape = ecotype)) + geom_errorbar( aes(ymin = fdsesmpd-se3, ymax = fdsesmpd+se3), position = position_dodge(0.3), width = 0.3)+ geom_point(aes(size=I(3)), position = position_dodge(0.3)) + theme_classic() + geom_line(aes(x = stage, y = fdsesmpd, color = ecotype,group = ecotype), position = position_dodge(0.3),linetype = "dashed", alpha = 0.6) + geom_hline(yintercept=0, linetype="dotted", color = "grey",size=0.8, alpha = 0.5) + scale_colour_manual(values = c("red4","darkgreen","navy"), name = "ecotype", labels = c("DRY","MESIC", "WET")) + theme(text = element_text(size = 13), legend.text = element_text(size=13), legend.direction = "horizontal") + xlab("Year") + ylab(bquote(FD[sesmpd])) + guides(color = guide_legend(nrow = 1)) # graph assembly ggarrange(p,q,r, labels = c("A", "B", "C"), label.x = 0.02, ncol = 1, nrow = 3, font.label = list(size = 13), common.legend = T, legend = "bottom", align = "v", legend.grob = get_legend(r)) ######## Hypothesis 2: the ITV's contribution to community trait variance # loading dataset & trait test figure cati=read.csv ("cati.csv", header=T,row.names=1) cati[,1:5] <- lapply(cati[,1:5], log) cati[,c("ecotype","spp")] <- lapply(cati[,c("ecotype","spp")], factor) tr.cati <- cati[,1:5] ind.cati <- cati[,6] spp.cati <- cati[,7] res <- Tstats(tr.cati, ind.cati, spp.cati, nperm = 999, independantTraits = T) plot(res,cex=0.001) # PCA # parallel analysis to retain no. of axis library(paran) paran(tr.cati,cfa=F) sppcode <- cati[,8] domsppcode <- cati[,10] ecot.pca <- prcomp(tr.cati, scale. = TRUE) ggbiplot(ecot.pca, obs.scale = 1, var.scale = 1, groups = sppcode, ellipse = TRUE, circle = T, labels = domsppcode, labels.size=4, varname.size = 0.001 ) + scale_color_discrete(name = '') + theme(legend.direction = 'horizontal', legend.position = 'none') + theme_classic() + theme(legend.position = "none") # species symbols should be added mannually in the PCA diagram