# 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