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

https://github.com/tom-n-walker/uphill-plants-soil-carbon
02 February 2026, 00:07:05 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
Revision 5c297ab275e1dd929f9b8db7c86d957ddf0fd6dd authored by Tom Walker on 07 September 2021, 14:31:53 UTC, committed by Tom Walker on 07 September 2021, 14:31:53 UTC
Added all analyses, streamlined pipelines and improved statistical models.
1 parent bd5cb92
  • Files
  • Changes
    • Branches
    • Releases
    • HEAD
    • refs/heads/main
    • 5c297ab275e1dd929f9b8db7c86d957ddf0fd6dd
    No releases to show
  • 75c5ddb
  • /
  • analysis_code
  • /
  • glasshouse_explain_respiration.R
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

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
  • snapshot
origin badgerevision badge
swh:1:rev:5c297ab275e1dd929f9b8db7c86d957ddf0fd6dd
origin badgedirectory badge
swh:1:dir:8cafe5307d20fe509d5d742c142d86d1d1a1b039
origin badgecontent badge
swh:1:cnt:c800b082f63e78122b113487fe967ac43774d86b
origin badgesnapshot badge
swh:1:snp:f252339e0fa3d80494e5af363a2625a847a65462

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
  • snapshot
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 ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 5c297ab275e1dd929f9b8db7c86d957ddf0fd6dd authored by Tom Walker on 07 September 2021, 14:31:53 UTC
Added all analyses, streamlined pipelines and improved statistical models.
Tip revision: 5c297ab
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–2026, 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