library(tidyverse) library(viridis) library(see) setwd("~/PIERRE") ################ figure 3 ############## load("HOLES_HYPERVOL/results/volumes_sites.Rdata") load("HOLES_HYPERVOL/results/NULL_volumes_summary.Rdata") svg("HOLES_HYPERVOL/results/histogram_HR_sites.svg", width = 7, height = 4, pointsize = 12) png("HOLES_HYPERVOL/results/histogram_HR_sites2.png", width = 700, height = 400, res=100) ggplot(NULL_summary_stats[NULL_summary_stats$pool != "regional" & NULL_summary_stats$site != "INVASION_Adelboden",], aes(x=fct_reorder(site, mean_temp))) + geom_col(aes(y = hollowness_ratio, fill = pool), position = "dodge")+ # geom_col(aes(y = null_mean_hollowness_ratio + 2*null_sd_hollowness_ratio, group = pool), position = "dodge", fill="red")+ geom_crossbar(aes(ymin = null_mean_hollowness_ratio - (2*null_sd_hollowness_ratio), y = null_mean_hollowness_ratio, ymax = null_mean_hollowness_ratio + (2*null_sd_hollowness_ratio), group = pool), position = "dodge", fill = "red", col = NA)+ scale_fill_viridis_d()+ geom_hline(yintercept = 0, linetype = 2)+ coord_flip()+ labs(y="Hollowness Ratio", x="")+ theme_modern() # theme(axis.text.x = element_text(angle = 45, hjust = 1)) dev.off() vol_sites %>% group_by(pool) %>% summarize("mean" = mean(hollowness_ratio, na.rm=T), "sd" = sd(hollowness_ratio,na.rm=T), "min" = min(hollowness_ratio, na.rm=T), "max" = max(hollowness_ratio, na.rm=T),) svg("HOLES_HYPERVOL/results/histogram_HV_sites.svg", width = 5, height = 5, pointsize = 12) ggplot(vol_sites, aes(y = hollow_vol , x=fct_reorder(site, mean_temp))) + geom_col(aes(fill = pool), position = "dodge")+ # facet_wrap(~pool)+ scale_fill_viridis_d(guide=F)+ coord_flip()+ labs(y="Hollow Volume", x="")+ theme_modern()+ ylim(0,160) # theme(axis.text.x = element_text(angle = 45, hjust = 1)) dev.off() svg("HOLES_HYPERVOL/results/histogram_FV_sites.svg", width = 5, height = 5, pointsize = 12) ggplot(vol_sites, aes(y = filled_vol , x=fct_reorder(site, mean_temp))) + geom_col(aes(fill = pool), position = "dodge")+ # facet_wrap(~pool)+ scale_fill_viridis_d(guide=F)+ coord_flip()+ labs(y="Filled Volume", x="")+ theme_modern()+ ylim(0,160) # theme(axis.text.x = element_text(angle = 45, hjust = 1)) dev.off() vol_sites2 <- vol_sites %>% select(-hollow_vol, -filled_vol) %>% spread(key = pool, value = hollowness_ratio) ggplot(vol_sites2, aes(y = (community - local)/regional, x=fct_reorder(site, mean_temp))) + geom_col(position = "dodge")+ scale_fill_viridis_d(guide=F)+ # coord_flip()+ labs(y="Hollowness Ratio", x="")+ theme_modern()+ theme(axis.text.x = element_text(angle = 45, hjust = 1)) ggplot(vol_sites, aes(y = hollowness_ratio, x=fct_reorder(site, mean_temp))) + geom_col(aes(fill = pool), position = "dodge")+ facet_wrap(~pool)+ scale_fill_viridis_d(guide=F)+ # coord_flip()+ labs(y="Hollowness Ratio", x="")+ theme_modern()+ theme(axis.text.x = element_text(angle = 45, hjust = 1)) ################# figure 4 ################## png("HOLES_HYPERVOL/results/hollow_fraction_temp.png", width = 600, height = 400, res=100) svg("HOLES_HYPERVOL/results/hollow_fraction_temp.svg", width=6, height = 4) ggplot(vol_sites[vol_sites$pool != "regional", ], aes(y = hollowness_ratio, x=mean_temp)) + stat_smooth(method = "lm", col= "darkgrey")+ # geom_hline(yintercept = regional_hollowness_ratio, colour="lightblue", size=2)+ geom_point(size=3, aes(color = pool))+ scale_color_viridis_d(guide = F)+ # geom_text(aes(label=site), nudge_y = -1)+ facet_wrap(~pool, ncol=3) + labs(x="monthly mean temperature (°C)", y="Hollowness Ratio", color="")+ theme_modern() dev.off() mod <- lm(hollowness_ratio ~ mean_temp:pool, data = vol_sites) summary(mod) ggplot(vol_sites, aes(y = hollow_vol, x=mean_temp)) + stat_smooth(method = "lm", col= "darkgrey")+ # geom_hline(yintercept = regional_hollowness_ratio, colour="lightblue", size=2)+ geom_point(size=3, aes(color = pool))+ scale_color_viridis_d(guide = F)+ # geom_text(aes(label=site), nudge_y = -1)+ facet_wrap(~pool, ncol=3) + labs(x="monthly mean temperature (°C)", y="Hollowness Ratio", color="")+ theme_modern() mod <- lm(hollowness_ratio ~ mean_temp, data = vol_sites[vol_sites$pool == "regional",]) summary(mod) mod <- lm(hollow_vol ~ mean_temp:pool, data = vol_sites) summary(mod) mod <- lm(hollowness_ratio ~ mean_temp, data = vol_sites[vol_sites$pool == "local",]) summary(mod) mod <- lm(hollow_vol ~ mean_temp, data = vol_sites[vol_sites$pool == "local",]) mod <- lm(hollowness_ratio ~ mean_temp, data = vol_sites[vol_sites$pool == "community",]) summary(mod) mod <- lm(hollow_vol ~ mean_temp, data = vol_sites[vol_sites$pool == "community",]) ######## other environmental gradients png("HOLES_HYPERVOL/results/hollow_fraction_ppt.png", width = 700, height = 400, res=100) svg("HOLES_HYPERVOL/results/hollow_fraction_ppt.svg", width=7, height = 4) ggplot(vol_sites, aes(y = hollowness_ratio, x=annual_ppt)) + # stat_smooth(method = "lm", col= "darkgrey")+ # geom_hline(yintercept = regional_hollowness_ratio, colour="lightblue", size=2)+ geom_point(size=3, aes(color = pool))+ scale_color_viridis_d(guide = F)+ # geom_text(aes(label=site), nudge_y = -1)+ facet_wrap(~pool, ncol=3) + labs(x="annual precipitation (mm)", y="Hollow volume ratio")+ theme_modern() dev.off() mod <- lm(hollowness_ratio ~ annual_ppt:pool, data = vol_sites) summary(mod) mod <- lm(hollowness_ratio ~ annual_ppt, data = vol_sites[vol_sites$pool == "regional",]) summary(mod) mod <- lm(hollowness_ratio ~ annual_ppt, data = vol_sites[vol_sites$pool == "local",]) summary(mod) mod <- lm(hollowness_ratio ~ annual_ppt, data = vol_sites[vol_sites$pool == "community",]) summary(mod) png("HOLES_HYPERVOL/results/hollow_fraction_prod.png", width = 700, height = 400, res=100) svg("HOLES_HYPERVOL/results/hollow_fraction_prod.svg", width=7, height = 4) ggplot(vol_sites, aes(y = hollowness_ratio, x=max_productivity)) + # stat_smooth(method = "lm", col= "darkgrey")+ # geom_hline(yintercept = regional_hollowness_ratio, colour="lightblue", size=2)+ geom_point(size=3, aes(color = pool))+ scale_color_viridis_d()+ # geom_text(aes(label=site), nudge_y = -1)+ facet_wrap(~pool, ncol=3) + labs(x="Maximum productivity (t.ha−1.year−1)", y="Hollow volume ratio")+ theme_modern() dev.off() mod <- lm(hollowness_ratio ~ max_productivity:pool, data = vol_sites) summary(mod) mod <- lm(hollowness_ratio ~ max_productivity, data = vol_sites[vol_sites$pool == "regional",]) summary(mod) mod <- lm(hollowness_ratio ~ max_productivity, data = vol_sites[vol_sites$pool == "local",]) summary(mod) mod <- lm(hollowness_ratio ~ max_productivity, data = vol_sites[vol_sites$pool == "community",]) summary(mod) png("HOLES_HYPERVOL/results/hollow_fraction_Na.png", width = 700, height = 400, res=100) svg("HOLES_HYPERVOL/results/hollow_fraction_Na.svg", width=7, height = 4) ggplot(vol_sites, aes(y = hollowness_ratio, x=Na)) + stat_smooth(method = "lm", col= "darkgrey")+ # geom_hline(yintercept = regional_hollowness_ratio, colour="lightblue", size=2)+ geom_point(size=3, aes(color = pool))+ scale_color_viridis_d()+ # geom_text(aes(label=site), nudge_y = -1)+ facet_wrap(~pool, ncol=3) + labs(x="Nitrogen soil content", y="Hollow volume ratio")+ theme_modern() mod <- lm(hollowness_ratio ~ Na:pool, data = vol_sites) summary(mod) mod <- lm(hollowness_ratio ~ Na, data = vol_sites[vol_sites$pool == "regional",]) summary(mod) mod <- lm(hollowness_ratio ~ Na, data = vol_sites[vol_sites$pool == "local",]) summary(mod) mod <- lm(hollowness_ratio ~ Na, data = vol_sites[vol_sites$pool == "community",]) summary(mod) ############## figure 5 ###################### load("HOLES_HYPERVOL/results/holesRandomPoints_withSitesConditions.Rdata") load("HOLES_HYPERVOL/results/regional_volume_list.Rdata") load("HOLES_HYPERVOL/results/scaling_factor.Rdata") load("HOLES_HYPERVOL/results/volumes_sites.Rdata") load("HOLES_HYPERVOL/results/sites_list.Rdata") convexExpectationRandomPoints <- sample_n(as.data.frame(regional_volumes_list@HVList$Reg.Conv.Expectation@RandomPoints),5000) convexExpectationRandomPoints$La. <- convexExpectationRandomPoints$La * scaling_factor_10000ind[["La","sigma"]] + scaling_factor_10000ind[["La","mu"]] convexExpectationRandomPoints$G. <- convexExpectationRandomPoints$G * scaling_factor_10000ind[["G","sigma"]] + scaling_factor_10000ind[["G","mu"]] convexExpectationRandomPoints$HMax. <- convexExpectationRandomPoints$HMax * scaling_factor_10000ind[["HMax","sigma"]] + scaling_factor_10000ind[["HMax","mu"]] convexExpectationRandomPoints$DDMin. <- convexExpectationRandomPoints$DDMin * scaling_factor_10000ind[["DDMin","sigma"]] + scaling_factor_10000ind[["DDMin","mu"]] convexExpectationRandomPoints <- rbind(convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints) convexExpectationRandomPoints$site <- rep(sites_list, each = 5000) convexExpectationRandomPoints <- left_join(convexExpectationRandomPoints, vol_sites) holesRandomPoints <- holesRandomPoints[holesRandomPoints$pool != "regional", ] library(see) svg("HOLES_HYPERVOL/results/holes_description_La.svg", width=6, height = 8) ggplot(holesRandomPoints[holesRandomPoints$type != "Hypervolume" ,], aes(y = La., x = fct_reorder(site, mean_temp)))+ geom_violinhalf(aes(fill = pool), col=NA, scale="count")+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type == "Hypervolume",], col=NA, fill ="darkgrey", alpha=0.5, scale="count")+ scale_fill_viridis_d(guide = F)+ facet_wrap(~pool)+ coord_flip()+ theme_modern() dev.off() holesRandomPoints[holesRandomPoints$type != "Hypervolume",] %>% group_by(pool) %>% summarize("mean" = mean(La., na.rm=T), "sd" = sd (La.,na.rm=T)) holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$mean_temp <5,] %>% group_by(pool) %>% summarize("mean" = mean(La., na.rm=T), "sd" = sd (La.,na.rm=T)) holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$mean_temp >5,] %>% group_by(pool) %>% summarize("mean" = mean(La., na.rm=T), "sd" = sd (La.,na.rm=T)) svg("HOLES_HYPERVOL/results/holes_description_DDMin.svg", width=6, height = 8) ggplot(holesRandomPoints[holesRandomPoints$type != "Hypervolume",], aes(y = DDMin., x = fct_reorder(site, mean_temp)))+ geom_violinhalf(aes(fill = pool), col=NA, scale="count")+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type == "Hypervolume",], aes(y = DDMin., x = fct_reorder(site, mean_temp)), col=NA, fill ="darkgrey", alpha=0.5, scale="count")+ scale_fill_viridis_d(guide = F)+ facet_wrap(~pool)+ coord_flip()+ theme_modern() dev.off() holesRandomPoints[holesRandomPoints$type != "Hypervolume",] %>% group_by(pool) %>% summarize("mean" = mean(DDMin., na.rm=T), "sd" = sd (DDMin.,na.rm=T)) holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$mean_temp <5,] %>% group_by(pool) %>% summarize("mean" = mean(DDMin., na.rm=T), "sd" = sd (DDMin.,na.rm=T)) holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$mean_temp >5,] %>% group_by(pool) %>% summarize("mean" = mean(DDMin., na.rm=T), "sd" = sd (DDMin.,na.rm=T)) svg("HOLES_HYPERVOL/results/holes_description_G.svg", width=6, height = 8) ggplot(holesRandomPoints[holesRandomPoints$type != "Hypervolume",], aes(y = G., x = fct_reorder(site, mean_temp)))+ geom_violinhalf(aes(fill = pool), col=NA, scale="count")+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type == "Hypervolume",], aes(y = G., x = fct_reorder(site, mean_temp)), col=NA, fill ="darkgrey", alpha=0.5, scale="count")+ scale_fill_viridis_d(guide = F)+ facet_wrap(~pool)+ coord_flip()+ theme_modern() dev.off() holesRandomPoints[holesRandomPoints$type != "Hypervolume",] %>% group_by(pool) %>% summarize("mean" = mean(G., na.rm=T), "sd" = sd (G.,na.rm=T)) holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$mean_temp <5,] %>% group_by(pool) %>% summarize("mean" = mean(G., na.rm=T), "sd" = sd (G.,na.rm=T)) holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$mean_temp >5,] %>% group_by(pool) %>% summarize("mean" = mean(G., na.rm=T), "sd" = sd (G.,na.rm=T)) svg("HOLES_HYPERVOL/results/holes_description_HMax.svg", width=6, height = 8) ggplot(holesRandomPoints[holesRandomPoints$type != "Hypervolume",], aes(y = HMax., x = fct_reorder(site, mean_temp)))+ geom_violinhalf(aes(fill = pool), col=NA, scale="count")+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type == "Hypervolume",], aes(y = HMax., x = fct_reorder(site, mean_temp)), col=NA, fill ="darkgrey", alpha=0.5, scale="count")+ scale_fill_viridis_d(guide = F)+ facet_wrap(~pool)+ coord_flip()+ theme_modern() dev.off() holesRandomPoints[holesRandomPoints$type != "Hypervolume",] %>% group_by(pool) %>% summarize("mean" = mean(HMax., na.rm=T), "sd" = sd (HMax.,na.rm=T)) holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$mean_temp <5,] %>% group_by(pool) %>% summarize("mean" = mean(HMax., na.rm=T), "sd" = sd (HMax.,na.rm=T)) holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$mean_temp >5,] %>% group_by(pool) %>% summarize("mean" = mean(HMax., na.rm=T), "sd" = sd (HMax.,na.rm=T)) svg("HOLES_HYPERVOL/results/sites_temperature.svg", width=4, height = 8) ggplot(vol_sites[vol_sites$pool == "local",], aes(y = mean_temp, x = fct_reorder(site, mean_temp) ))+ geom_point()+ geom_line(aes(group = 1))+ theme_modern()+ coord_flip() dev.off() ############# other possibility for figure 6 ############### ## create vector of random points from convex expectation convexExpectationRandomPoints <- sample_n(as.data.frame(regional_volumes_list@HVList$Reg.Conv.Expectation@RandomPoints),5000) convexExpectationRandomPoints$La. <- convexExpectationRandomPoints$La * scaling_factor_10000ind[["La","sigma"]] + scaling_factor_10000ind[["La","mu"]] convexExpectationRandomPoints$G. <- convexExpectationRandomPoints$G * scaling_factor_10000ind[["G","sigma"]] + scaling_factor_10000ind[["G","mu"]] convexExpectationRandomPoints$HMax. <- convexExpectationRandomPoints$HMax * scaling_factor_10000ind[["HMax","sigma"]] + scaling_factor_10000ind[["HMax","mu"]] convexExpectationRandomPoints$DDMin. <- convexExpectationRandomPoints$DDMin * scaling_factor_10000ind[["DDMin","sigma"]] + scaling_factor_10000ind[["DDMin","mu"]] convexExpectationRandomPoints <- rbind(convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints, convexExpectationRandomPoints) convexExpectationRandomPoints$site <- rep(sites_list, each = 5000) convexExpectationRandomPoints <- left_join(convexExpectationRandomPoints, vol_sites) svg("HOLES_HYPERVOL/results/holes_description_HMax.svg", width=4, height = 8) ggplot() + geom_violinhalf(data = convexExpectationRandomPoints, aes(y = HMax., x=fct_reorder(site, mean_temp)), col=NA, fill ="grey", scale="count")+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "regional",], aes(y = HMax., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[1], scale="count", alpha = 0.75)+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "local",], aes(y = HMax., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[15], scale="count", alpha = 0.75)+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "community",], aes(y = HMax., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[30], scale="count", alpha = 0.75)+ # scale_fill_viridis_d(guide = F)+ # facet_wrap(~pool)+ coord_flip()+ theme_modern() dev.off() svg("HOLES_HYPERVOL/results/holes_description_G.svg", width=4, height = 8) ggplot() + geom_violinhalf(data = convexExpectationRandomPoints, aes(y = G., x=fct_reorder(site, mean_temp)), col=NA, fill ="darkgrey", scale="count")+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "regional",], aes(y = G., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[1], scale="count", alpha = 0.75)+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "local",], aes(y = G., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[15], scale="count", alpha = 0.75)+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "community",], aes(y = G., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[30], scale="count", alpha = 0.75)+ # scale_fill_viridis_d(guide = F)+ # facet_wrap(~pool)+ coord_flip()+ theme_modern() dev.off() svg("HOLES_HYPERVOL/results/holes_description_La.svg", width=4, height = 8) ggplot() + geom_violinhalf(data = convexExpectationRandomPoints, aes(y = La., x=fct_reorder(site, mean_temp)), col=NA, fill ="darkgrey", scale="count")+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "regional",], aes(y = La., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[1], scale="count", alpha = 0.75)+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "local",], aes(y = La., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[15], scale="count", alpha = 0.75)+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "community",], aes(y = La., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[30], scale="count", alpha = 0.75)+ # scale_fill_viridis_d(guide = F)+ # facet_wrap(~pool)+ coord_flip()+ theme_modern() dev.off() svg("HOLES_HYPERVOL/results/holes_description_DDMin.svg", width=4, height = 8) ggplot() + geom_violinhalf(data = convexExpectationRandomPoints, aes(y = DDMin., x=fct_reorder(site, mean_temp)), col=NA, fill ="darkgrey", scale="count")+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "regional",], aes(y = DDMin., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[1], scale="count", alpha = 0.75)+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "local",], aes(y = DDMin., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[15], scale="count", alpha = 0.75)+ geom_violinhalf(data = holesRandomPoints[holesRandomPoints$type != "Hypervolume" & holesRandomPoints$pool == "community",], aes(y = DDMin., x = fct_reorder(site, mean_temp)), col=NA, fill = viridis(30)[30], scale="count", alpha = 0.75)+ # scale_fill_viridis_d(guide = F)+ # facet_wrap(~pool)+ coord_flip()+ theme_modern() dev.off() #################################### figure supplementary LM by environment axis ################# svg("HOLES_HYPERVOL/results/holes_temperature_HMax.svg", width=8, height = 4) ggplot(holesRandomPoints[holesRandomPoints$type != "Hypervolume",], aes(y = HMax., x = mean_temp, col = pool))+ geom_point(col="grey", alpha=0.01)+ stat_smooth(method="lm", col="black")+ stat_summary(fun.data = "mean_cl_boot", geom = 'pointrange')+ scale_color_viridis_d(guide = F)+ facet_wrap(~pool)+ theme_modern()+ labs(x="Mean temperature (°C)", y="Maximum height", color="") dev.off() library(visreg) mod <- lm(HMax. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "regional" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) mod <- lm(HMax. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "local" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) mod <- lm(HMax. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "community" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) svg("HOLES_HYPERVOL/results/holes_temperature_G.svg", width=8, height = 4) ggplot(holesRandomPoints[holesRandomPoints$type != "Hypervolume",], aes(y = G., x = mean_temp, col = pool))+ geom_point(col="grey", alpha=0.01)+ stat_smooth(method="lm", col="black")+ stat_summary(fun.data = "mean_cl_boot", geom = 'pointrange')+ scale_color_viridis_d(guide = F)+ facet_wrap(~pool)+ theme_modern()+ labs(x="Mean temperature (°C)", y="Growth rate", color="") dev.off() mod <- lm(G. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "regional" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) mod <- lm(G. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "local" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) mod <- lm(G. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "community" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) svg("HOLES_HYPERVOL/results/holes_temperature_DDMin.svg", width=8, height = 4) ggplot(holesRandomPoints[holesRandomPoints$type != "Hypervolume",], aes(y = DDMin., x = mean_temp, col = pool))+ geom_point(col="grey", alpha=0.01)+ stat_smooth(method="lm", col="black")+ stat_summary(fun.data = "mean_cl_boot", geom = 'pointrange')+ scale_color_viridis_d(guide = F)+ facet_wrap(~pool)+ theme_modern()+ labs(x="Mean temperature (°C)", y="Minimum degree day", color="") dev.off() mod <- lm(DDMin. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "regional" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) mod <- lm(DDMin. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "local" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) mod <- lm(DDMin. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "community"& holesRandomPoints$type != "Hypervolume", ]) summary(mod) svg("HOLES_HYPERVOL/results/holes_temperature_La.svg",width=8, height = 4) ggplot(holesRandomPoints[holesRandomPoints$type != "Hypervolume",], aes(y = La., x = mean_temp, col = pool))+ geom_point(col="grey", alpha=0.01)+ stat_smooth(method="lm", col="black")+ stat_summary(fun.data = "mean_cl_boot", geom = 'pointrange')+ scale_color_viridis_d(guide = F)+ facet_wrap(~pool)+ theme_modern()+ labs(x="Mean temperature (°C)", y="Shade tolerance", color="") dev.off() mod <- lm(La. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "regional"& holesRandomPoints$type != "Hypervolume", ]) summary(mod) mod <- lm(La. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "local" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) mod <- lm(La. ~ mean_temp, data = holesRandomPoints[holesRandomPoints$pool == "community"& holesRandomPoints$type != "Hypervolume", ]) summary(mod) ##########figure 6 altogether ######## mod <- lm(mean_temp ~ HMax + G + La + DDMin, data = holesRandomPoints[holesRandomPoints$pool == "regional" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) visreg(mod) mod <- lm(mean_temp ~ HMax. + G. + La. + DDMin., data = holesRandomPoints[holesRandomPoints$pool == "local" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) visreg(mod) mod <- lm(mean_temp ~ HMax + G + La + DDMin, data = holesRandomPoints[holesRandomPoints$pool == "community" & holesRandomPoints$type != "Hypervolume", ]) summary(mod) visreg(mod) ######### Figure SUPPLEMENTARY sites productivity ################ load("HOLES_HYPERVOL/results/volumes_sites.Rdata") # plot site climatic space png("HOLES_HYPERVOL/results/sites_climateSpace_Prod.png", width=1500, height = 1500, res=200) ggplot(vol_sites[vol_sites$pool=="community",], aes(y = mean_temp, x = annual_ppt, fill = max_productivity, size=max_productivity)) + geom_point(shape=21) + geom_text(aes(label=site), size = 4, nudge_y = -0.25, nudge_x = -30)+ scale_fill_viridis()+ scale_size(guide=F)+ theme_modern()+ labs(x="annual precipitation (mm)", y="mean annual temperature (°C)", fill="Maximum productivity (t.ha−1.year−1)")+ theme(legend.position = "bottom") dev.off() ggplot(vol_sites[vol_sites$pool=="community",], aes(y = max_productivity, x = Na, col=max_productivity)) + geom_point(size=4) + geom_text(aes(label=site), nudge_y = -0.25)+ scale_color_gradient(low = "darkgrey", high = "darkgreen")+ theme_modern() labs(x="annual precipitation (mm)", y="monthly mean temperature (°C)", color="Maximum productivity (t.ha−1.year−1)")+ theme(legend.position = "bottom") plot3d(x =vol_sites[vol_sites$pool=="community","mean_temp"], y = vol_sites[vol_sites$pool=="community","annual_ppt"], z = vol_sites[vol_sites$pool=="community","Na"], size = 15, colors = vol_sites[vol_sites$pool=="community","max+_produtivity"]) mod <- lm(max_productivity ~ mean_temp, data = vol_sites[vol_sites$pool=="community",] ) plot(mod) summary(mod) # map sites library(raster) library(rgdal) library(ggplot2) library(rasterVis) library(grid) library(scales) library(viridis) # better colors for everyone library(ggthemes) test <- raster("DATA/hillshade1x1.tif") relief <- raster("DATA/02-relief-georef-clipped-resampled.tif") relief <- raster("DATA/elevation1x1_new.tif") relief <- raster("DATA/Swiss_topo_Shade_WGS84.tif") relief_spdf <- as(relief, "SpatialPixelsDataFrame") # relief is converted to a very simple data frame, # just as the fortified municipalities. # for that we need to convert it to a # SpatialPixelsDataFrame first, and then extract its contents # using as.data.frame relief <- as.data.frame(relief_spdf) %>% rename(value = "Swiss_topo_Shade_WGS84") # remove unnecessary variables rm(relief_spdf) temp <- getData('worldclim', var='bio', res=0.5, lon=8, lat=47) temp2 <- mask(temp, relief) swiss <- getData('GADM', country='CHE', level=0) along the plot(swiss) temp2 <- mask(temp, swiss) plot(temp2) ggplot() + # raster comes as the first layer, municipalities on top geom_raster(data = relief, aes(x = x, y = y, alpha = value)) + # use the "alpha hack" scale_alpha(name = "", range = c(0.6, 0), guide = F)+ geom_point(data = ) + geom_point(data=vol_sites, aes(x=longitude, y=latitude)) + theme_classic()+ lims(x = c(min(coordinates(relief)[,"x"]), max(coordinates(relief)[,"x"])), y= c(min(coordinates(relief)[,"y"]), max(coordinates(relief)[,"y"])))+ coord_fixed(ratio = 1) test_spdf <- as(test, "SpatialPixelsDataFrame") test_df <- as.data.frame(test_spdf) colnames(test_df) <- c("value", "x", "y") gplot(test) + geom_raster(aes(alpha = value)) + # geom_point(data=vol_sites, aes(x=longitude, y=latitude)) + # scale_fill_gr() + coord_equal() + theme_map() + theme(legend.position="bottom") + theme(legend.key.width=unit(2, "cm")) ggplot() + geom_tile(data=test, aes(x=x, y=y, fill=value)) + geom_point(data=vol_sites, aes(x=longitude, y=latitude)) + scale_fill_viridis() + coord_equal() + theme_map() + theme(legend.position="bottom") + theme(legend.key.width=unit(2, "cm")) #Mosaic/merge srtm tiles srtmmosaic <- mosaic(srtm, srtm2, srtm3, fun=mean) getData() ggplot(vol_sites[vol_sites$pool=="community",], aes(y = max_productivity, x = mean_temp)) + geom_point(size=4) + geom_text(aes(label=site), nudge_y = -0.1)+ scale_color_viridis_c()+ theme_light()+ labs(x="monthly mean temperature (°C)", y="maximum productivity (t.ha−1.year−1)")+ theme(legend.position = "bottom") ggplot(vol_sites[vol_sites$pool=="community",], aes(y = max_productivity, x = annual_ppt)) + geom_point(size=4) + geom_text(aes(label=site), nudge_y = -0.1)+ scale_color_viridis_c()+ theme_light()+ labs(x="annual precipitation (mm)", y="maximum productivity (t.ha−1.year−1)")+ theme(legend.position = "bottom") ############# supplementary hypervolumes plots################ # create list of sites sites_list <- list.files(path="Capsis_dev_2/data/forceps/pierre", full.names = T, pattern="output-cmd2_PG_*") %>% str_sub(start = 49, end = -5) #iterations through site list site <- "GrandeDixence" for(site in sites_list){ print(site) png(paste("HOLES_HYPERVOL/results/hypervolume_plot_regional_", site,".png", sep=''), width = 800, height = 800, res=100) plot(hypervolume_join(regional_hypervolumes_list[[site]]), limits = c(-3,5), colors = c("grey60", viridis(20)[c(1,1)], "grey60","grey60"), # colors = c("lightblue","darkblue","red1", "red2", "red3", "red4", "darkred"), cex.names = 3, cex.centroid = 2, cex.random = 0.5, show.data = F, show.contour = T, show.random = T) dev.off() png(paste("HOLES_HYPERVOL/results/hypervolume_plot_local_",site,".png", sep=''), width = 800, height = 800, res=100) plot(hypervolume_join( # regional_volumes_list@HVList$Reg.Conv.Expectation, local_hypervolumes_list[[site]]), limits = c(-3,5), colors = c("grey60",viridis(20)[c(10)], "grey30", "grey30", "grey30", "grey30", "grey30"), # colors = c("black","darkblue","red1", "red2", "red3", "red4", "darkred"), cex.names = 3, cex.centroid = 2, cex.random = 0.5, show.data = F, show.contour = T, show.random = T) dev.off() png(paste("HOLES_HYPERVOL/results/hypervolume_plot_community_",site,".png", sep=''), width = 800, height = 800, res=100) plot(hypervolume_join( # regional_volumes_list@HVList$Reg.Conv.Expectation, # local_hypervolumes_list[["Bever"]]@HVList$`Local Hypervolume - GrandeDixence`, community_hypervolumes_list[[site]]), limits = c(-3,5), colors = c("grey60", viridis(20)[c(19,19, 19)], "grey30", "grey30", "grey30", "grey30", "grey30"), # colors = c("black","darkblue","red1", "red2", "red3", "red4", "darkred"), cex.names = 3, cex.centroid = 2, cex.random = 0.5, show.data = F, show.contour = T, show.random = T) dev.off() } ############# supplementary hypervolumes plots 3D ################ library(hypervolume) load("HOLES_HYPERVOL/results/regional_volume_list.Rdata") load("HOLES_HYPERVOL/results/local_hypervolumes_list.Rdata") load("HOLES_HYPERVOL/results/community_hypervolumes_list.Rdata") # create list of sites sites_list <- list.files(path="Capsis_dev_2/data/forceps/pierre", full.names = T, pattern="output-cmd2_PG_*") %>% str_sub(start = 49, end = -5) #iterations through site list site <- "GrandeDixence" for(site in sites_list){ print(site) # plot(hypervolume_join(regional_volumes_list@HVList$Regional.Hypervol, # regional_volumes_list@HVList$Regional.Hole.1, # regional_volumes_list@HVList$Regional.Hole.2), # limits = c(-3,5), show.3d = T, show.frame=T, show.legend=F, # plot.3d.axes.id=c("HMax", "DDMin", "G"), # colors = c("grey60", viridis(20)[c(1, 1, 1, 1)]), # # colors = c("lightblue","darkblue","red1", "red2", "red3", "red4", "darkred"), # cex.names = 0, cex.centroid = 0, # cex.random = 6, show.data = F, show.contour = T, show.random = T) plot(regional_volumes_list@HVList$Regional.Hypervol, limits = c(-3,5), show.3d = T, show.frame=T, show.legend=F, # plot.3d.axes.id=c("HMax", "DDMin", "G"), colors = "grey", # colors = c("lightblue","darkblue","red1", "red2", "red3", "red4", "darkred"), cex.names = 0, cex.centroid = 0, cex.random = 8, show.data = F, show.contour = T, show.random = T) plot(hypervolume_join( local_hypervolumes_list[[site]]), limits = c(-3,5),show.3d = T, show.legend=F, # plot.3d.axes.id=c("HMax", "DDMin", "G"), colors = c("grey", viridis(20)[c(1, 1 ,1, 1)]), # colors = c("black","darkblue","red1", "red2", "red3", "red4", "darkred"), cex.names = 0, cex.centroid = 0, cex.random = 8, show.data = F, show.contour = T, show.random = T) plot(hypervolume_join( # regional_volumes_list@HVList$Reg.Conv.Expectation, # local_hypervolumes_list[["Bever"]]@HVList$`Local Hypervolume - GrandeDixence`, community_hypervolumes_list[[site]]), show.3d = T,show.legend=F, # plot.3d.axes.id=c("HMax", "DDMin", "G"), limits = c(-3,5), colors = c("grey", viridis(20)[c(20,20,20,20)]), # colors = c("black","darkblue","red1", "red2", "red3", "red4", "darkred"), cex.names = 0, cex.centroid = 0, cex.random = 8, show.data = F, show.contour = T, show.random = T) hypervolume_save_animated_gif(image.size = 1000, axis = c(0, 0, 1), rpm = 4, duration = 15, fps = 10, file.name = paste("HOLES_HYPERVOL/results/3dPlot_", site,sep=""), directory.output = ".") }