# keep examples from using more than 2 cores
data.table::setDTthreads(Sys.getenv("OMP_THREAD_LIMIT", unset = 2))
# example data
data(sp1)
# usually best to adjust margins
par(mar = c(0,0,3,0))
# add color vector
sp1$soil_color <- with(sp1, munsell2rgb(hue, value, chroma))
# promote to SoilProfileCollection
depths(sp1) <- id ~ top + bottom
# init horizon designation
hzdesgnname(sp1) <- 'name'
# plot profiles
plotSPC(sp1, id.style = 'side')
# title, note line argument:
title('Sample Data 1', line = 1, cex.main = 0.75)
# plot profiles without horizon-line divisions
plotSPC(sp1, divide.hz = FALSE)
# diagonal lines encode horizon boundary distinctness
sp1$hzD <- hzDistinctnessCodeToOffset(sp1$bound_distinct)
plotSPC(sp1, hz.distinctness.offset = 'hzD', name.style = 'center-center')
# plot horizon color according to some property
data(sp4)
depths(sp4) <- id ~ top + bottom
hzdesgnname(sp4) <- 'name'
plotSPC(sp4, color = 'clay')
# another example
data(sp2)
depths(sp2) <- id ~ top + bottom
hzdesgnname(sp2) <- 'name'
site(sp2) <- ~ surface
# some of these profiles are very deep, truncate plot at 400cm
# label / re-order with site-level attribute: `surface`
plotSPC(sp2, label = 'surface', plot.order = order(sp2$surface),
max.depth = 400)
# example using a categorical attribute
plotSPC(sp2, color = "plasticity",
max.depth = 400)
# plot two SPC objects in the same figure
par(mar = c(1,1,1,1))
# plot the first SPC object and
# allocate space for the second SPC object
plotSPC(sp1, n = length(sp1) + length(sp2))
# plot the second SPC, starting from the first empty space
plotSPC(sp2, x.idx.offset = length(sp1), add = TRUE)
##
## demonstrate horizon designation shrinkage
##
data("jacobs2000")
# shrink "long" horizon names
plotSPC(
jacobs2000,
name = 'name',
name.style = 'center-center',
shrink = TRUE,
cex.names = 0.8
)
# shrink horizon names in "thin" horizons
plotSPC(
jacobs2000,
name = 'name',
name.style = 'center-center',
shrink = TRUE,
shrink.thin = 15,
cex.names = 0.8,
)
##
## demonstrate adaptive legend
##
data(sp3)
depths(sp3) <- id ~ top + bottom
# make some fake categorical data
horizons(sp3)$fake.data <- sample(letters[1:15], size = nrow(sp3), replace=TRUE)
# better margins
par(mar=c(0,0,3,1))
# note that there are enough colors for 15 classes (vs. previous limit of 10)
# note that the legend is split into 2 rows when length(classes) > n.legend argument
plotSPC(sp3, color='fake.data', name='fake.data', cex.names=0.8)
# make enough room in a single legend row
plotSPC(sp3, color='fake.data', name='fake.data', cex.names=0.8, n.legend=15)
##
## demonstrate y.offset argument
## must be of length 1 or length(x)
##
# example data and local copy
data("jacobs2000")
x <- jacobs2000
hzdesgnname(x) <- 'name'
# y-axis offsets, simulating a elevation along a hillslope sequence
# same units as horizon depths in `x`
# same order as profiles in `x`
y.offset <- c(-5, -10, 22, 65, 35, 15, 12)
par(mar = c(0, 0, 2, 2))
# y-offset at 0
plotSPC(x, color = 'matrix_color', cex.names = 0.66)
# constant adjustment to y-offset
plotSPC(x, color = 'matrix_color', cex.names = 0.66, y.offset = 50)
# attempt using invalid y.offset
# warning issued and default value of '0' used
# plotSPC(x, color = 'matrix_color', cex.names = 0.66, y.offset = 1:2)
# variable y-offset
# fix overlapping horizon depth labels
par(mar = c(0, 0, 1, 0))
plotSPC(
x,
y.offset = y.offset,
color = 'matrix_color',
cex.names = 0.75,
shrink = TRUE,
hz.depths = TRUE,
hz.depths.offset = 0.05,
fixLabelCollisions = TRUE,
name.style = 'center-center'
)
# random y-axis offsets
yoff <- runif(n = length(x), min = 1, max = 100)
# random gradient of x-positions
xoff <- runif(n = length(x), min = 1, max = length(x))
# note profiles overlap
plotSPC(x,
relative.pos = xoff,
y.offset = yoff,
color = 'matrix_color',
cex.names = 0.66,
hz.depths = TRUE,
name.style = 'center-center'
)
# align / adjust relative x positions
set.seed(111)
pos <- alignTransect(xoff, x.min = 1, x.max = length(x), thresh = 0.65)
# y-offset is automatically re-ordered according to
# plot.order
par(mar = c(0.5, 0.5, 0.5, 0.5))
plotSPC(x,
plot.order = pos$order,
relative.pos = pos$relative.pos,
y.offset = yoff,
color = 'matrix_color',
cex.names = 0.66,
hz.depths = TRUE,
name.style = 'center-center'
)
box()
Run the code above in your browser using DataLab