Profile Summaries

D.E. Beaudette
2015-12-18
This document is based on aqp version 1.9.3 and soilDB version 1.6.7.

Introduction

# load required libaries
library(soilDB)
library(lattice)
library(reshape2)
library(plyr)

# get all pedons from the selected set
x <- fetchNASIS(rmHzErrors = FALSE, nullFragsAreZero = FALSE)

# init vector of taxonnames to keep
soils <- c("Whiterock", "Copperopolis", "Shabarudo", "Dunstone", "Loafercreek", "Argonaut", "Crimeahouse", 
    "Hennekenot")

# convert vector of taxonnames into REGEX pattern for matching
pat <- paste0(soils, collapse = "|")

# subset pedons that match our REGEX pattern
idx <- grep(pat, x$taxonname, ignore.case = TRUE)
x <- x[idx, ]

# normalize taxonname via REGEX matching
for (i in soils) x$taxonname[grep(i, x$taxonname, ignore.case = TRUE)] <- i

# aggregate data by normalized taxonname, via slice-wise mean
a.colors <- slab(x, taxonname ~ m_r + m_g + m_b + clay + phfield + total_frags_pct, slab.fun = mean, 
    na.rm = TRUE)

# throw out aggregate data that are deeper than 150cm
a.colors <- subset(a.colors, subset = bottom < 150)

# convert long -> wide format
x.colors <- dcast(a.colors, taxonname + top + bottom ~ variable, value.var = "value")

# check
head(a.colors)
variable taxonname value top bottom contributing_fraction
m_r Argonaut 0.4295949 0 1 0.80
m_r Argonaut 0.4295949 1 2 0.80
m_r Argonaut 0.4340744 2 3 0.90
m_r Argonaut 0.4350552 3 4 0.90
m_r Argonaut 0.4322111 4 5 0.95
m_r Argonaut 0.4404747 5 6 0.95
head(x.colors)
taxonname top bottom m_r m_g m_b clay phfield total_frags_pct
Argonaut 0 1 0.4295949 0.2722286 0.1651937 18.30000 6.014286 3.875
Argonaut 1 2 0.4295949 0.2722286 0.1651937 18.30000 6.014286 3.875
Argonaut 2 3 0.4340744 0.2742672 0.1634346 17.75000 6.020000 5.900
Argonaut 3 4 0.4350552 0.2739248 0.1614330 18.16667 6.020000 6.400
Argonaut 4 5 0.4322111 0.2729369 0.1613046 18.66667 6.033333 6.000
Argonaut 5 6 0.4404747 0.2766611 0.1661813 19.58333 6.033333 6.750
# composite RGB triplets into an R-compatible color note that missing colors must be padded with NA
x.colors$soil_color <- NA
not.na <- which(complete.cases(x.colors[, c("m_r", "m_g", "m_b")]))
x.colors$soil_color[not.na] <- with(x.colors[not.na, ], rgb(m_r, m_g, m_b, maxColorValue = 1))

# aggregate bedrock depth probabilty by taxonname at 90% level of confidence
dp <- aggregateSoilDepth(x, "taxonname", crit.prob = 0.9)

# init a new SoilProfileCollection from aggregate data
depths(x.colors) <- taxonname ~ top + bottom
# join-in our depth to contact data
site(x.colors) <- dp

# generate index for new ordering
new.order <- match(c("Whiterock", "Copperopolis", "Shabarudo", "Dunstone", "Loafercreek", "Argonaut", 
    "Crimeahouse", "Hennekenot"), profile_id(x.colors))
par(mar = c(1, 0, 3, 0))
plot(x.colors, divide.hz = FALSE, name = "", plot.order = new.order, col.label = "Soil Color", lwd = 1.25, 
    axis.line.offset = -6, cex.depth.axis = 1, cex.id = 1)
addBracket(x.colors$soil.top, x.colors$soil.bottom, col = "black", label = "P(soil >= 90%)", label.cex = 0.85)
title("Aggregate Soil Properties (mean)")

sdfsdfsdf


par(mar = c(1, 0, 3, 0))
plot(x.colors, divide.hz = FALSE, color = "clay", name = "", plot.order = new.order, col.label = "Clay Content (%)", 
    lwd = 1.25, axis.line.offset = -6, cex.depth.axis = 1, cex.id = 1)
addBracket(x.colors$soil.top, x.colors$soil.bottom, col = "black", label = "P(soil >= 90%)", label.cex = 0.85)

plot(x.colors, divide.hz = FALSE, color = "phfield", name = "", plot.order = new.order, col.label = "pH", 
    lwd = 1.25, axis.line.offset = -6, cex.depth.axis = 1, cex.id = 1)
addBracket(x.colors$soil.top, x.colors$soil.bottom, col = "black", label = "P(soil >= 90%)", label.cex = 0.85)

plot(x.colors, divide.hz = FALSE, color = "total_frags_pct", name = "", plot.order = new.order, col.label = "Total Rock Fragment Volume (%)", 
    lwd = 1.25, axis.line.offset = -6, cex.depth.axis = 1, cex.id = 1)
addBracket(x.colors$soil.top, x.colors$soil.bottom, col = "black", label = "P(soil >= 90%)", label.cex = 0.85)

sdfsdfsdf