Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
shows calculations for organic matter as mass/mass or volume/volume using a 1 square meter section to a 2 cm depth as an example
## OM246 on a volume basis
## starting thought: what is 5% OM by mass on a volume basis?
library(ggplot2)
library(cowplot)
## assign bulk densities; these don't vary, nor does compressibility
bd_sand <- 1.56
bd_om <- 0.22
## calculates bulk density of a mixed material
## given the measured OM value on a mass basis
bulk_density <- function(om) {
bd <- 100 / ((om / bd_om) + ((100 - om) / bd_sand))
return(bd)
}
## simulate data with OM to 2 cm depth from 0 to 100%
d <- data.frame(om2 = seq(0, 100, 1))
d$bd2 <- bulk_density(d$om2)
### I calculate this on a square meter basis
### This is the mass of a soil layer to 2 cm depth
### and 100 by 100 cm
d$mass2 <- d$bd2 * 2 * 100 * 100
## This is the OM on a mass basis
d$om2mass <- d$om2 / 100 * d$mass2
## The volume of that mass of OM
d$vol <- d$om2mass / bd_om
## OM mass as a percent of soil mass
d$mass_percent <- d$om2mass / d$mass2 * 100
## OM volume as a percent of soil volume
d$vol_percent <- d$vol / (2 * 100 * 100) * 100
## make a chart
p <- ggplot(data = d,
aes(x = mass_percent,
y = vol_percent))
yo <- p + theme_cowplot(font_family = "Roboto Condensed") +
background_grid() +
geom_line(colour = "#002b36") +
scale_y_continuous(breaks = seq(0, 100, 10),
expand = expansion(mult = c(0, 0.05))) +
scale_x_continuous(breaks = seq(0, 100, 2),
limits = c(0, 20),
expand = expansion(mult = c(0, 0.05))) +
labs(x = "Organic material by mass %",
y = "Organic material by volume %",
caption = expression(paste("Calculated for a bulk density of 1.56 g/",
cm^{3},
" for sand and 0.22 g/",
cm^{3},
" for organic material.")),
title = "Calculated conversions between soil organic material by mass & by volume") +
theme(plot.caption = element_text(size = 8)) +
annotate("segment",
x = 5,
xend = 5,
y = 0,
yend = 26.5,
colour = "#cb4b16",
size = 0.5,
arrow=arrow(type = 'closed',
length = unit(0.3, 'cm'))) +
annotate("label",
colour = "#cb4b16",
fill = "#eee8d5",
x = 5.25,
y = 13,
hjust = 0,
family = "Roboto Condensed",
label = "When the OM by mass is 5%,\nthe OM by volume is 27%.") +
annotate("label",
colour = "#cb4b16",
fill = "#eee8d5",
x = 2,
y = 55,
hjust = 0,
family = "Roboto Condensed",
label = "The standard reporting units for soil\norganic material on soil tests is mass.\nThat is, the mass of organic material\nper mass of soil. Here's what it works out\nto in volume.") +
annotate("segment",
x = 12.5,
xend = 12.5,
y = 0,
yend = 50,
colour = "#859900",
size = 0.5,
arrow=arrow(type = 'closed',
length = unit(0.3, 'cm'))) +
annotate("label",
colour = "#859900",
fill = "#eee8d5",
x = 13,
y = 45,
hjust = 0,
family = "Roboto Condensed",
label = "When the OM by mass is 12.5%,\nOM by volume is 50%.")
yo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment