Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 06a84f27dcdea4b2af9702349faf415ea13e8103 authored by tom-n-walker on 08 September 2021, 06:48:30 UTC, committed by GitHub on 08 September 2021, 06:48:30 UTC
Update README.md
1 parent 0222df8
  • Files
  • Changes
  • 6f23340
  • /
  • analysis_code
  • /
  • glasshouse_explain_respiration.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:06a84f27dcdea4b2af9702349faf415ea13e8103
directory badge Iframe embedding
swh:1:dir:05d94a61b18166edb87d5d48ac8d2c21e44bb59a
content badge Iframe embedding
swh:1:cnt:c800b082f63e78122b113487fe967ac43774d86b

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
glasshouse_explain_respiration.R
################################################################################
#### Project: Lowland plant migrations alpine soil C loss
#### Title:   Glasshouse plant effects on soil
#### Author:  Tom Walker (thomas.walker@usys.ethz.ch)
#### Date:    31 May 2021
#### ---------------------------------------------------------------------------


#### PROLOGUE ------------------------------------------------------------------

## Options ----
# remove objects from global environment
rm(list = ls())
# R session options (no factors, bias against scientific #s)
options(
  stringsAsFactors = F,
  scipen = 6
)

## Source functions ----
source("./r_code/apply_mice.R")

## Libraries ----
# standard library set
library(nlme)
library(tidyverse)


#### DATA ----------------------------------------------------------------------

## Load from drake cache ----
# all glasshouse data
gh <- readd(gh_soil)
# subset
gh_plants <- gh$pot_plants
gh_soil <- gh$pot_soil
gh_pots <- left_join(gh_plants, gh_soil)


#### PCA of CWM TRAITS ---------------------------------------------------------

# build
pcaPlants <- prcomp(
  apply_mice(select(gh_pots, AGB.g:cGS.umol.m2.s), 5),
  scale = T, center = T
)
# put scores into pot data frame
gh_pots$plantsPC1 <- pcaPlants$x[, 1]
gh_pots$plantsPC2 <- pcaPlants$x[, 2]
# extract loadings
loadings <- pcaPlants$rotation[, 1:2] %>%
  as.data.frame %>%
  rownames_to_column("variable") %>%
  mutate(variable = fct_reorder(variable, PC1, min))


#### ANALYSE -------------------------------------------------------------------

# PCA scores of traits on initial microbial respiration
m1 <- lme(
  intMR.ugC.g.h ~ plantsPC1 + treatment * plantsPC2,
  random = ~ 1 | block,
  method = "ML",
  data = gh_pots,
  na.action = na.exclude
)
# diagnose
r1 <- residuals(m1, type = "pearson")
par(mfrow = c(1, 3))
plot(r1 ~ fitted(m1))
boxplot(r1 ~ gh_pots$treatment)
hist(r1)
# main effects
drop1(m1, test = "Chisq")


#### PLOT ----------------------------------------------------------------------

# scores
pc1Plot <- ggplot(gh_pots) +
  aes(x = plantsPC1, y = intMR.ugC.g.h) +
  theme_bw() +
  theme(panel.grid = element_blank()) +
  guides(col = "none", fill = "none") +
  scale_fill_manual(values = c("#43978D", "#F9AD6A")) +
  scale_color_manual(values = c("#43978D", "#F9AD6A")) +
  geom_point(aes(fill = treatment), shape = 21) +
  geom_smooth(method = "lm", se = F, fullrange = T, col = "black") +
  labs(x = "PC1 score", y = expression(paste("Initial R (µg C ", g^{-1}, " ", h^{-1}, ")")))
pc2Plot <- ggplot(gh_pots) +
  aes(x = plantsPC2, y = intMR.ugC.g.h) +
  theme_bw() +
  theme(panel.grid = element_blank()) +
  guides(col = "none", fill = "none") +
  scale_fill_manual(values = c("#43978D", "#F9AD6A")) +
  scale_color_manual(values = c("#43978D", "#F9AD6A")) +
  geom_point(aes(fill = treatment), shape = 21) +
  geom_smooth(aes(col = treatment), method = "lm", se = F, fullrange = T) +
  labs(x = "PC2 score", y = expression(paste("Initial R (µg C ", g^{-1}, " ", h^{-1}, ")")))
# loadings
pc1loads <- ggplot(loadings) +
  aes(x = variable, y = PC1) +
  theme_bw() +
  theme(panel.grid = element_blank()) +
  scale_y_continuous(limits = c(-0.5, 0.7)) +
  geom_segment(aes(yend = 0, xend = variable)) +
  geom_point(shape = 21, fill = "white") +
  geom_hline(yintercept = 0) +
  coord_flip() +
  labs(x = "", y = "PC1 loading (49.0% var.)")
pc2loads <- ggplot(loadings) +
  aes(x = variable, y = PC2) +
  theme_bw() +
  theme(panel.grid = element_blank()) +
  scale_y_continuous(limits = c(-0.5, 0.7)) +
  geom_segment(aes(yend = 0, xend = variable)) +
  geom_point(shape = 21, fill = "white") +
  geom_hline(yintercept = 0) +
  coord_flip() +
  labs(x = "", y = "PC2 loading (19.3% var.)")
# put together
cowplot::plot_grid(pc1Plot, pc2Plot, pc1loads, pc2loads,
                   nrow = 2, align = "hv")
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API