This is a work in progress, please see the in-line comments for a description of what is going on here.

# load required libraries
library(soilDB)
library(aqp)
library(sharpshootR)
library(sp)

# sample data from soilDB packaeg
data("loafercreek")

# keep first 10 profiles
x <- loafercreek[1:10, ]

# default margins are too wide, make smaller
par(mar=c(1,1,2,1))

# profile sketches
plot(x, label='pedon_id', id.style='side')

# group profiles by hillslope position
groupedProfilePlot(x, 'hillslopeprof', label='pedon_id', id.style='side')

# extract site data so that we can annotate wit PSCS depths
s <- site(x)

# reminder of ID used by SPC
idname(x)
## [1] "peiid"
# subset site data into ID and PSCS top / bottom 
s <- s[, c('peiid', 'psctopdepth', 'pscbotdepth')]

# re-name for addBrackets() function
names(s)[2:3] <- c('top', 'bottom') 

# plot sketches and annotate with PSCS
par(mar=c(1,1,1,1))
# ommit pedon IDs for now
plot(x, print.id=FALSE)
# add PSCS brackets as vertical var
addBracket(s, tick.length = 0, lwd=10, col=rgb(red=0, green=0, blue=1, alpha=0.25))

# check structure of diagnostic horizon data
head(diagnostic_hz(x))
##    peiid           featkind featdept featdepb
## 1  64505    ochric epipedon        1        5
## 2  64505   argillic horizon       15       79
## 3  64505 paralithic contact       79      107
## 4  64505     lithic contact      107       NA
## 5 115595    ochric epipedon        0       10
## 6 115595   argillic horizon       10       74
# tabulate and sort
sort(table(diagnostic_hz(x)$featkind))
## 
##                       anthropic epipedon                   abrupt textural change 
##                                        0                                        0 
##                    andic soil properties                           calcic horizon 
##                                        0                                        0 
##                                durinodes                      petrocalcic horizon 
##                                        0                                        0 
##                                 fragipan                           gypsic horizon 
##                                        0                                        0 
##                                   gilgai                          glossic horizon 
##                                        0                                        0 
##                         aquic conditions                          histic epipedon 
##                                        0                                        0 
##                          sombric horizon                      petrogypsic horizon 
##                                        0                                        0 
##                           placic horizon                           kandic horizon 
##                                        0                                        0 
##                     secondary carbonates                          mollic epipedon 
##                                        0                                        0 
##                         melanic epipedon                           natric horizon 
##                                        0                                        0 
##                         plaggen epipedon                      petroferric contact 
##                                        0                                        0 
##                               permafrost                                plinthite 
##                                        0                                        0 
##                            albic horizon                            agric horizon 
##                                        0                                        0 
##                           spodic horizon                             slickensides 
##                                        0                                        0 
##                          umbric epipedon                         sulfuric horizon 
##                                        0                                        0 
##                             oxic horizon                            salic horizon 
##                                        0                                        0 
##                                  duripan                       sulfidic materials 
##                                        0                                        0 
##        interfingering of albic materials                    fibric soil materials 
##                                        0                                        0 
##                     hemic soil materials                    sapric soil materials 
##                                        0                                        0 
##                      humilluvic material                         limnic materials 
##                                        0                                        0 
##                        coprogenous earth                       diatomaceous earth 
##                                        0                                        0 
##                                     marl                          albic materials 
##                                        0                                        0 
##            mottles with chroma 2 or less                                 lamellae 
##                                        0                                        0 
##                                 ortstein                   fragic soil properties 
##                                        0                                        0 
##                           densic contact                         densic materials 
##                                        0                                        0 
##                     paralithic materials                     anhydrous conditions 
##                                        0                                        0 
##                            cryoturbation                          gelic materials 
##                                        0                                        0 
##                             glacic layer                        folistic epipedon 
##                                        0                                        0 
##                     redox concentrations   redox depletions with chroma 2 or less 
##                                        0                                        0 
##                           reduced matrix                           endosaturation 
##                                        0                                        0 
##                            episaturation                       anthric saturation 
##                                        0                                        0 
##                 lithologic discontinuity strongly contrasting particle size class 
##                                        0                                        0 
##                     gypsum accumulations                       salt accumulations 
##                                        0                                        0 
##                           volcanic glass                            n value > 0.7 
##                                        0                                        0 
##                         spodic materials                                artifacts 
##                                        0                                        0 
##                                   fibers                          free carbonates 
##                                        0                                        0 
##                       resistant minerals                     weatherable minerals 
##                                        0                                        0 
##                       anhydritic horizon                   human-altered material 
##                                        0                                        0 
##               human-transported material                       manufactured layer 
##                                        0                                        0 
##               manufactured layer contact                           cambic horizon 
##                                        0                                        1 
##                           lithic contact                          ochric epipedon 
##                                        2                                        9 
##                         argillic horizon                       paralithic contact 
##                                        9                                        9
# add brackets for some diagnostic features
addDiagnosticBracket(x, kind='argillic horizon', col='red')
addDiagnosticBracket(x, kind='paralithic contact', col='black')

# experiment with re-ordering sketches
# order according to elevation as described in the field
new.order <- order(x$elev_field)
new.order
##  [1]  8  2  3  9 10  7  1  4  5  6
# plot profiles in the new order
par(mar=c(4.5,1,1,1))
plot(x, plot.order=new.order, print.id=FALSE)

# the "brackets" will automatically follow the new ordering
addBracket(s, tick.length = 0, lwd=10, col=rgb(red=0, green=0, blue=1, alpha=0.25))
addDiagnosticBracket(x, kind='argillic horizon', col='red')
addDiagnosticBracket(x, kind='paralithic contact', col='black')

# add an axis with elevation associated with each profile
axis(side=1, at = 1:length(x), labels = x$elev_field[new.order], line = 1)
mtext('Elevation (m)', side = 1, line = 3.25)

Test out some new features in aqp.

par(mar=c(4.5,1,3,1))
plot(x, color='total_frags_pct', plot.order=new.order, print.id=FALSE)

# the "brackets" will automatically follow the new ordering
addBracket(s, tick.length = 0, lwd=10, col=rgb(red=0, green=0, blue=1, alpha=0.25))
addDiagnosticBracket(x, kind='argillic horizon', col='red')
addDiagnosticBracket(x, kind='paralithic contact', col='black')

addVolumeFraction(x, 'total_frags_pct')

plot(x, color='total_frags_pct', plot.order=new.order, print.id=FALSE, relative.pos=jitter(1:length(x)))

# the "brackets" will automatically follow the new ordering
addBracket(s, tick.length = 0, lwd=10, col=rgb(red=0, green=0, blue=1, alpha=0.25))
addDiagnosticBracket(x, kind='argillic horizon', col='red')
addDiagnosticBracket(x, kind='paralithic contact', col='black')

addVolumeFraction(x, 'total_frags_pct')

plot(x, color='total_frags_pct', print.id=FALSE, relative.pos=jitter(1:length(x)))

# the "brackets" will automatically follow the new ordering
addBracket(s, tick.length = 0, lwd=10, col=rgb(red=0, green=0, blue=1, alpha=0.25))
addDiagnosticBracket(x, kind='argillic horizon', col='red')
addDiagnosticBracket(x, kind='paralithic contact', col='black')

addVolumeFraction(x, 'total_frags_pct')

## plot data as a transect, using coordinates and elevation

# initialize spatial object in SPC
coordinates(x) <- ~ x_std + y_std
# set coordinate reference system (CRS)
proj4string(x) <- '+proj=longlat +datum=WGS84'

# this example requires projected coordinates, units of meters
# we provide a local, projected CRS: UTM z10 NAD83
par(mar=c(4.5,4,1,1))
plotTransect(x, grad.var.name = 'elev_field', crs = CRS('+proj=utm +zone=10 +datum=NAD83'))

## better example from CA792
# this requires the latest soilDB from github
# devtools::install_github("ncss-tech/soilDB", dependencies=FALSE, upgrade_dependencies=FALSE)
data("mineralKing")

par(mar=c(1,1,2,1))
groupedProfilePlot(mineralKing, groups='taxonname', print.id=FALSE)

# init coordinates
coordinates(mineralKing) <- ~ x_std + y_std
proj4string(mineralKing) <- '+proj=longlat +datum=NAD83'

# local CRS
crs.utm <- CRS('+proj=utm +zone=11 +datum=NAD83')

par(mar=c(4.5,4,4,1))
plotTransect(mineralKing, grad.var.name='elev_field', crs=crs.utm, grad.axis.title='Elevation (m)', label='pedon_id')

plotTransect(mineralKing, grad.var.name='elev_field', crs=crs.utm, grad.axis.title='Elevation (m)', label='pedon_id', color='clay')

Tinker with relative sketch positioning.

# standard transect plot, profile sketches arranged along integer sequence
plotTransect(mineralKing, grad.var.name='elev_field', crs=crs.utm, grad.axis.title='Elevation (m)', label='pedon_id', name='hzname')

# default behavior, attempt adjustments to prevent over-plot and preserve relative spacing
# use set.seed() to fix outcome
plotTransect(mineralKing, grad.var.name='elev_field', crs=crs.utm, grad.axis.title='Elevation (m)', label='pedon_id', name='hzname', width=0.15, spacing = 'relative')

# attempt relative positioning based on scaled distances, no corrections for overlap
# profiles are clustered in space and therefore over-plot
plotTransect(mineralKing, grad.var.name='elev_field', crs=crs.utm, grad.axis.title='Elevation (m)', label='pedon_id', name='hzname', width=0.15, spacing = 'relative', fix.relative.pos = FALSE)

# customize arguments to aqp::fixOverlap()
plotTransect(mineralKing, grad.var.name='elev_field', crs=crs.utm, grad.axis.title='Elevation (m)', label='pedon_id', name='hzname', width=0.15, spacing = 'relative', fix.relative.pos = list(maxIter=6000, trace=TRUE, adj=0.2, thresh=0.7))

# load example dataset
data(gopheridge)

# randomly select 20 profiles
gopheridge <- sample(gopheridge, 20)

# define a new function
# get hz mid-point of hz with max clay content
f.max.clay.depth <- function(x) {
  h <- horizons(x)
  max.clay <- which.max(h$clay)
  res <- with(h[max.clay, ], (hzdept+hzdepb) / 2)
  return(res)
}

# apply function to each profile
# results are put into @site
gopheridge$max.clay.depth <- profileApply(gopheridge, f.max.clay.depth)


# plot and annotate with max clay depths
par(mar=c(0,0,0,0))
plot(gopheridge, name='hzname', print.id=FALSE)
x.pos <- 1:length(gopheridge)
points(x.pos, gopheridge$max.clay.depth, col='white', pch=21, cex=0.75, bg='black')

##
# see ?sp5 examples

This document is based on aqp version 1.17.06, soilDB version 2.3.9, and sharpshootR version 1.4.03.