Introduction

This tutorial describes a simple process for visualizing patterns in categorical data associated with pedon data.

Adapting Content to Your Data

Copy and paste blocks of code in this tutorial into a new R Studio script file (ctrl + shift + n makes a new file), edit, and then run. Running lines or blocks of code in an RStudio script file is as simple as moving the cursor to the line (or selecting a block) of code and press ctrl + enter.

Setup R Environment

This step is only required the first time you open R. These packages will be available via library() in later sessions.

With a recent version of R (>= 2.15), it is possible to get all of the packages that this tutorial depends on via:

# run these commands in the R console, only once
install.packages('aqp', dep=TRUE) # stable version from CRAN + dependencies
install.packages('soilDB', dep=TRUE) # stable version from CRAN + dependencies
install.packages('sharpshootR', dep=TRUE) # stable version from CRAN + dependencies

Examples

The following examples are based on the loafercreek example dataset from the soilDB package. This is a good example of the type of SoilProfileCollection object returned by fetchNASIS(from='pedons'). The

library(aqp)
library(sharpshootR)

# load some example NASIS data
data(loafercreek, package='soilDB')

# cut-down to a subset
loafercreek <- loafercreek[1:20, ]

# get depth class
sdc <- getSoilDepthClass(loafercreek)

# check it out
head(sdc)
##    peiid depth very.shallow shallow mod.deep  deep very.deep depth.class
## 1  64505    79        FALSE   FALSE     TRUE FALSE     FALSE    mod.deep
## 2 115595    74        FALSE   FALSE     TRUE FALSE     FALSE    mod.deep
## 3 115819    74        FALSE   FALSE     TRUE FALSE     FALSE    mod.deep
## 4 115827    79        FALSE   FALSE     TRUE FALSE     FALSE    mod.deep
## 5 207255    73        FALSE   FALSE     TRUE FALSE     FALSE    mod.deep
## 6 249585    79        FALSE   FALSE     TRUE FALSE     FALSE    mod.deep
# join back into site-level attributes
site(loafercreek) <- sdc

# diagnostic properties to consider, no need to convert to factors
# these are stored in the site-level attributes of the SPC
v <- c('lithic.contact', 'paralithic.contact', 'argillic.horizon', 
       'cambic.horizon', 'ochric.epipedon', 'mollic.epipedon', 'very.shallow',
       'shallow', 'mod.deep', 'deep', 'very.deep')


# presence / absense matrix of several diagnostic features
x <- diagnosticPropertyPlot(loafercreek, v, k=5, grid.label='bedrckkind', dend.label = 'taxonname')

x <- diagnosticPropertyPlot(loafercreek, v, k=5, grid.label='pedon_id', dend.label = 'taxonname')

x <- diagnosticPropertyPlot2(loafercreek, v, k=5, grid.label='pedon_id')

x <- diagnosticPropertyPlot2(loafercreek, v, k=5, grid.label='taxonname')

It is possible to include other categorical variables such as hillslope position. The multinominal2logical() is used to expand a set of categories into a matrix of TRUE/FALSE.

# work-around: new function in sharpshootR
hp <- multinominal2logical(loafercreek, 'hillslopeprof')

# check it out
head(hp)
##    peiid summit shoulder backslope footslope toeslope
## 1 115595  FALSE    FALSE     FALSE     FALSE    FALSE
## 2 115819  FALSE    FALSE     FALSE     FALSE    FALSE
## 3 115827  FALSE    FALSE     FALSE     FALSE    FALSE
## 4 207255  FALSE    FALSE      TRUE     FALSE    FALSE
## 5 249585  FALSE    FALSE      TRUE     FALSE    FALSE
## 6 252820  FALSE    FALSE      TRUE     FALSE    FALSE
# join back into site-level attributes
site(loafercreek) <- hp

# init variable names
v <- c('lithic.contact', 'paralithic.contact', 'argillic.horizon', 
       'ochric.epipedon', 'mollic.epipedon', 'mod.deep', 'deep', 'very.deep', levels(loafercreek$hillslope_pos))

# should work as before
# use the 'sort.vars = FALSE' option to set the order of the variable names to the order they are listed in 'v'
x <- diagnosticPropertyPlot(loafercreek, v, k=5, grid.label='bedrckkind', dend.label = 'taxonname', sort.vars = FALSE)

x <- diagnosticPropertyPlot2(loafercreek, v, k=5, grid.label='bedrckkind', sort.vars = FALSE)


This document is based on sharpshootR version 1.3.5, aqp version 1.15.3, and soilDB version 2.0-1.