Learn R Programming

aqp (version 1.6)

addBracket: Add Depth Brackets

Description

Add depth-wise brackets to an existing plot of a SoilProfileCollection object.

Usage

addBracket(idx, top, bottom, tick.length = 0.05, 
arrow.length = 0.05, offset = -0.3, missing.bottom.depth = 25, 
...)

Arguments

idx
vector of integers, related to profile order: see details
top
numeric vector of bracket top depths
bottom
numeric vector of bracket bottom depths
tick.length
length of bracket "tick" mark
arrow.length
length of arrowhead
offset
numeric, length of left-hand offset from each profile
missing.bottom.depth
distance (in depth units) to extend brackets that are missing a lower depth
...
further arguments passed on to segments or arrows

Details

The idx argument is an integer index linking depth bracket top/bottom depths to a sketch of profiles generated by plot.SoilProfileCollection. See examples below.

See Also

plotSPC

Examples

Run this code
# sample data
data(sp1)

# add color vector
sp1$soil_color <- with(sp1, munsell2rgb(hue, value, chroma))

# promote to SoilProfileCollection
depths(sp1) <- id ~ top + bottom

# plot profiles
plot(sp1)

# manually add depth bracket with + bottom
addBracket(1, 5, 75)
# mannual add depth bracket with no bottom depth
addBracket(2, 40, col='red')

# extract top/bottom depths associated with all A horizons
f <- function(i) {
  h <- horizons(i)
  idx <- grep('^A', h$name)
  c(min(h$top[idx]), max(h$bottom[idx], na.rm=TRUE))
}

# apply function to sp1, result is a list
a <- profileApply(sp1, f, simplify=FALSE)
# convert list into matrix
a <- do.call('rbind', a)

# generate index linking our top/bottom depths with original ordering
key <- match(row.names(a), profile_id(sp1))

# plot
plot(sp1)
# annotate with brackets 
addBracket(key, a[, 1], a[, 2])

# more interesting example using diagnostic horizons
if(require(soilDB)) {
  # load some sample data with diagnostic horizons
  data(loafercreek)
  
  # extract first 15 profiles
  x <- loafercreek[1:15, ]
  s <- site(x)

  # plot
  par(mar=c(0,0,0,0))
  plot(x, name='hzname', id.style='top')
  
  # add bracket describing the particle size control section, 
  # from site-level data
  addBracket(match(s$pedon_id, profile_id(x)), 
  s$psctopdepth, s$pscbotdepth, offset=-0.4)
  
  # add brackets describing the argillic horizon
  addDiagnosticBracket(x, 'argillic horizon', col='red')
  # add brackets describing paralithic contact
  addDiagnosticBracket(x, 'paralithic contact', col='blue')
}

Run the code above in your browser using DataLab