ca630 {aqp} | R Documentation |
Site and laboratory data from soils sampled in the central Sierra Nevada Region of California.
data(ca630)
List containing:
$site : A data frame containing site information.
user_site_id
national user site id
mlra
the MLRA
county
the county
ssa
soil survey area
lon
longitude, WGS84
lat
latitude, WGS84
pedon_key
national soil profile id
user_pedon_id
local soil profile id
cntrl_depth_to_top
control section top depth (cm)
cntrl_depth_to_bot
control section bottom depth (cm)
sampled_taxon_name
soil series name
$lab : A data frame containing horizon information.
pedon_key
national soil profile id
layer_key
national horizon id
layer_sequence
horizon sequence number
hzn_top
horizon top (cm)
hzn_bot
horizon bottom (cm)
hzn_desgn
horizon name
texture_description
USDA soil texture
nh4_sum_bases
sum of bases extracted by ammonium acetate (pH 7)
ex_acid
exchangeable acidity [method ?]
CEC8.2
cation exchange capacity by sum of cations method (pH 8.2)
CEC7
cation exchange capacity by ammonium acetate (pH 7)
bs_8.2
base saturation by sum of cations method (pH 8.2)
bs_7
base saturation by ammonium acetate (pH 7)
These data were extracted from the NSSL database. 'ca630' is a list composed of site and lab data, each stored as dataframes. These data are modeled by a 1:many (site:lab) relation, with the 'pedon_id' acting as the primary key in the 'site' table and as the foreign key in the 'lab' table.
library(plyr)
library(lattice)
library(Hmisc)
library(maps)
library(sp)
# check the data out:
data(ca630)
str(ca630)
## List of 2
## $ site:'data.frame': 137 obs. of 11 variables:
## ..$ user_site_id : chr [1:137] "90CA009101" "90CA009102" "90CA009103" "90CA009104" ...
## ..$ mlra : chr [1:137] "22" "22" "22" "22" ...
## ..$ county : chr [1:137] "CA009" "CA009" "CA009" "CA009" ...
## ..$ ssa : chr [1:137] "CA731" "CA731" "CA731" "CA731" ...
## ..$ lon : num [1:137] -120 -120 -120 -120 -120 ...
## ..$ lat : num [1:137] 38.4 38.4 38.4 38.4 38.3 ...
## ..$ pedon_key : chr [1:137] "91P0709" "91P0710" "91P0711" "91P0712" ...
## ..$ user_pedon_id : chr [1:137] "90CA009101" "90CA009102" "90CA009103" "90CA009104" ...
## ..$ cntrl_depth_to_top: int [1:137] NA 25 NA 0 25 NA 25 25 0 28 ...
## ..$ cntrl_depth_to_bot: int [1:137] NA 100 NA 30 100 NA 97 100 30 78 ...
## ..$ sampled_taxon_name: chr [1:137] "Windy" "Tallac" "Gerle" "Nd" ...
## $ lab :'data.frame': 571 obs. of 13 variables:
## ..$ pedon_key : chr [1:571] "91P0709" "91P0709" "91P0709" "91P0709" ...
## ..$ layer_key : chr [1:571] "91P04048" "91P04049" "91P04050" "91P04051" ...
## ..$ layer_sequence : int [1:571] 1 2 3 4 1 2 3 4 1 2 ...
## ..$ hzn_top : int [1:571] 0 30 79 119 0 25 46 71 0 25 ...
## ..$ hzn_bot : int [1:571] 30 79 119 218 25 46 71 107 25 58 ...
## ..$ hzn_desgn : chr [1:571] "A" "Bw1" "Bw2" "C" ...
## ..$ texture_description: chr [1:571] "Sandy loam" "Sandy loam" "Fine sandy loam" "Fine sandy loam" ...
## ..$ nh4_sum_bases : num [1:571] 9.9 1.3 0.9 0.8 10.1 1.4 0.8 0.2 1.7 0.5 ...
## ..$ ex_acid : num [1:571] 21.9 18.8 13.7 12.2 11.3 18.6 18.6 12 11.6 9.3 ...
## ..$ CEC8.2 : num [1:571] 31.8 20.1 14.6 13 21.4 20 19.4 12.2 13.3 9.8 ...
## ..$ CEC7 : num [1:571] 25.3 13.2 10.8 9 16.7 14.1 11.6 6.5 14.9 9.7 ...
## ..$ bs_8.2 : int [1:571] 31 6 6 6 47 7 4 2 13 5 ...
## ..$ bs_7 : int [1:571] 39 10 8 9 60 10 7 3 11 5 ...
# note that pedon_key is the link between the two tables
# make a copy of the horizon data
ca <- ca630$lab
# promote to a SoilProfileCollection class object
depths(ca) <- pedon_key ~ hzn_top + hzn_bot
# add site data, based on pedon_key
site(ca) <- ca630$site
# ID data missing coordinates: '|' is a logical OR
(missing.coords.idx <- which(is.na(ca$lat) | is.na(ca$lon)))
## [1] 48 56
# remove missing coordinates by safely subsetting
if(length(missing.coords.idx) > 0)
ca <- ca[-missing.coords.idx, ]
# register spatial data
coordinates(ca) <- ~ lon + lat
# assign a coordinate reference system
proj4string(ca) <- '+proj=longlat +datum=NAD83'
# check the result
print(ca)
## Object of class SoilProfileCollection
## Number of profiles: 113
## Depth range: 29-260 cm
##
## Horizon attributes:
## pedon_key layer_key layer_sequence hzn_top hzn_bot hzn_desgn
## 451 00P0780 00P04900 1 0 2 A
## 452 00P0780 00P04901 2 2 15 Bw1
## 453 00P0780 00P04902 3 15 30 Bw2
## 454 00P0780 00P04903 4 30 45 Cd
## 455 00P0781 00P04904 1 0 14 A
## 456 00P0781 00P04905 2 14 38 Bt1
## texture_description nh4_sum_bases ex_acid CEC8.2 CEC7 bs_8.2 bs_7
## 451 Loamy very fine sand 1.2 8.7 9.9 9.8 12 12
## 452 Fine sandy loam 0.4 11.2 11.6 5.7 3 7
## 453 Fine sandy loam 0.4 9.2 9.6 4.0 4 10
## 454 Fine sandy loam 0.4 3.9 4.3 1.7 9 24
## 455 Fine sandy loam 2.0 12.0 14.0 8.2 14 24
## 456 Fine sandy loam 1.1 20.8 21.9 11.7 5 9
##
## Sampling site attributes:
## pedon_key user_site_id mlra county ssa user_pedon_id
## 1 00P0780 00CA109001 22 CA109 CA790 00CA109001
## 2 00P0781 00CA109002 22 CA109 CA790 00CA109002
## 3 00P0783 00CA109004 22 CA109 CA790 00CA109004
## 4 00P0784 00CA109005 22 CA109 CA790 00CA109005
## 5 00P0785 00CA109006 22 CA109 CA790 00CA109006
## 6 00P0786 00CA109007 22 CA109 CA790 00CA109007
## cntrl_depth_to_top cntrl_depth_to_bot sampled_taxon_name
## 1 25 100 (unnamed)
## 2 14 64 (unnamed)
## 3 25 100 (unnamed)
## 4 25 100 (unnamed)
## 5 25 100 (unnamed)
## 6 25 100 (unnamed)
##
## Spatial Data:
## min max
## lon -120.71503 -119.15709
## lat 37.75437 38.45706
## [1] "+proj=longlat +datum=NAD83 +ellps=GRS80 +towgs84=0,0,0"
# map the data (several ways to do this, here is a simple way)
map(database='county', region='california')
points(coordinates(ca), col='red', cex=0.5)
# aggregate %BS 7 for all profiles into 1 cm slices
a <- slab(ca, fm= ~ bs_7)
# plot median & IQR by 1 cm slice
xyplot(
top ~ p.q50, data=a, lower=a$p.q25, upper=a$p.q75,
ylim=c(160,-5), alpha=0.5, scales=list(alternating=1, y=list(tick.num=7)),
panel=panel.depth_function, prepanel=prepanel.depth_function,
ylab='Depth (cm)', xlab='Base Saturation at pH 7',
par.settings=list(superpose.line=list(col='black', lwd=2))
)
# aggregate %BS at pH 8.2 for all profiles by MLRA, along 1 cm slices
# note that mlra is stored in @site
a <- slab(ca, mlra ~ bs_8.2)
# keep only MLRA 18 and 22
a <- subset(a, subset=mlra %in% c('18', '22'))
# plot median & IQR by 1 cm slice, using different colors for each MLRA
xyplot(
top ~ p.q50, groups=mlra , data=a, lower=a$p.q25, upper=a$p.q75,
ylim=c(160,-5), alpha=0.5, scales=list(y=list(tick.num=7, alternating=3), x=list(alternating=1)),
panel=panel.depth_function, prepanel=prepanel.depth_function,
ylab='Depth (cm)', xlab='Base Saturation at pH 8.2',
par.settings=list(superpose.line=list(col=c('black','blue'), lty=c(1,2), lwd=2)),
auto.key=list(columns=2, title='MLRA', points=FALSE, lines=TRUE)
)
# safely compute hz-thickness weighted mean CEC (pH 7)
# using data.frame objects
head(lab.agg.cec_7 <- ddply(ca630$lab, .(pedon_key),
.fun=summarise, CEC_7=wtd.mean(bs_7, weights=hzn_bot-hzn_top)))
## pedon_key CEC_7
## 1 00P0780 13.888889
## 2 00P0781 11.191489
## 3 00P0783 19.254545
## 4 00P0784 29.825000
## 5 00P0785 9.917722
## 6 00P0786 11.514286
# extract a SPDF with horizon data along a slice at 25 cm
s.25 <- slice(ca, fm=25 ~ bs_7 + CEC7 + ex_acid)
## result is a SpatialPointsDataFrame object
spplot(s.25, zcol=c('bs_7','CEC7','ex_acid'))
# note that the ordering is preserved:
all.equal(s.25$pedon_key, profile_id(ca))
## [1] TRUE
# extract a data.frame with horizon data at 10, 20, and 50 cm
s.multiple <- slice(ca, fm=c(10,20,50) ~ bs_7 + CEC7 + ex_acid)
# Extract the 2nd horizon from all profiles as SPDF
ca.2 <- ca[, 2]
## result is a SpatialPointsDataFrame object
# subset profiles 1 through 10
ca.1.to.10 <- ca[1:10, ]
# basic plot method: profile plot
plot(ca.1.to.10, name='hzn_desgn')