Continuing the previous discussion of pair-wise dissimilarity between soil profiles, the following demonstration (code, comments, and figures) further elaborates on the method. A more in-depth discussion of this example will be included as a vignette within the 1.0 release of AQP.

pc-demo-fig1.png

Total, Between-Profile Dissimilarity

# setup environment
library(aqp)
library(ape)
library(RColorBrewer)
library(latticeExtra)
library(plotrix)
# setup some colors
cols <- brewer.pal(3'Set1')
# setup horizon-level data: data are from lab sampled pedons
d <- structure(
        list(
        series = c("auburn""auburn""auburn""auburn""dunstone""dunstone""dunstone""dunstone""sobrante""sobrante""sobrante""sobrante""sobrante"),
        top = c(03152505173105102851),
        bottom = c(31525475173141510285174),
        clay = c(21212021161720211816151820),
        frags = c(613928131961502211312),
        ph = c(5.65.65.85.866.36.36.35.85.75.86.26.2)
        ),
        .Names = c("series""top""bottom""clay""frags""ph"),
        row.names = c(NA-13L),
        class = "data.frame"
        )
# establish site-level data
s <- data.frame(
        series=c('auburn''dunstone''sobrante'),
        precip=c(243032),
        stringsAsFactors=FALSE
        )
# generate fake horizon names with clay / frags / ph
d$name <- with(dpaste(clayfragsphsep='/'))
# upgrade to SoilProfile Collection object
depths(d) <- series ~ top + bottom
site(d) <- s
# inspect variables used to determine dissimilarity
cloud(clay ~ ph + fragsgroups=seriesdata=horizons(d)auto.key=list(columns=3points=TRUElines=FALSE)par.settings=list(superpose.symbol=list(pch=16col=colscex=1.5)))
# compute betwee-profile dissimilarity, no depth weighting
d.dis <- profile_compare(dvars=c('clay''ph''frags')k=0max_d=61replace_na=TRUEadd_soil_flag=TRUE)
# check total, between-profile dissimilarity, normalized to maximum
d.m <- signif(as.matrix(d.dis / max(d.dis))2)
print(d.m)
# group via divisive hierarchical clustering
d.diana <- diana(d.dis)
# convert classes, for better plotting
d.phylo <- as.phylo(as.hclust(d.diana))
# plot: 2 figures side-by-side
par(mfcol=c(1,2))
# profiles
plot(dwidth=0.1name='name')
# annotate shallow-mod.deep break
abline(h=50col='red'lty=2)
# add dissimilarity matrix
addtable2plot(0.870format(d.mdigits=2)display.rownames=TRUExjust=0yjust=0cex=0.6title='Total Dissimilarity')
# plot dendrogram in next panel
plot(d.phylodirection='down'srt=0font=1label.offset=1)
X

pc-demo-fig2.png
Image: Profile Dissimilarity Demo: MVO Soils, Slice-Wise Dissimilarity

Slice-wise, Between-Profile Dissimilarity

# continuing from example above...
# return dissimilarity matrices at each depth slice
d.dis.all <- profile_compare(dvars=c('clay''ph''frags')k=0max_d=61replace_na=TRUEadd_soil_flag=TRUEreturn_depth_distances=TRUE)
# check between-profile dissimilarity, at slice 1
print(as.matrix(d.dis.all[[1]]))
# init functions for extracting pair-wise dissimilarity:
f.12 <- function(i) as.matrix(i)[12] # between auburn and dunstone
f.13 <- function(i) as.matrix(i)[13] # between auburn and sobrante
f.23 <- function(i) as.matrix(i)[23] # between dunstone and sobrante
# apply functions at each slice
d.12 <- sapply(d.dis.allf.12)
d.13 <- sapply(d.dis.allf.13)
d.23 <- sapply(d.dis.allf.23)
# combine into single data.frame
d.all <- make.groups(
        auburn.dunstone=data.frame(slice=1:61d=d.12d.sum=cumsum(d.12)),
        auburn.sobrante=data.frame(slice=1:61d=d.13d.sum=cumsum(d.13)),
        dunstone.sobrante=data.frame(slice=1:61d=d.23d.sum=cumsum(d.23))
        )
# plot slice-wise dissimilarity between all three soils
p.1 <- xyplot(slice ~ dgroups=whichdata=d.allylim=c(62,0)type=c('l','g')xlim=c(0.2,1.2)ylab='Depth (cm)'xlab=''horizontal=TRUEauto.key=list(columns=3lines=TRUEpoints=FALSE)asp=1)
# plot slice-wise, cumulative dissimilarity between all three soils
p.2 <- xyplot(slice ~ d.sumgroups=whichdata=d.allylim=c(62,0)type=c('l','g')ylab='Depth (cm)'xlab=''horizontal=TRUEauto.key=list(columns=3lines=TRUEpoints=FALSE)asp=1)
# combine into panels of a single figure
p.3 <- c('Slice-Wise Distance'=p.1'Cumulative Distance'=p.2)
# setup plotting style
trellis.par.set(superpose.line=list(col=colslwd=2lty=c(1,2,4))strip.background=list(col=grey(0.85)))
# render figure
print(p.3)
X