#Load packages
library(GSIF)
library(soiltexture)
library(aqp)
library(plyr)
TT.plot( class.sys = "none" )
TT.plot( class.sys = "USDA.TT" )

#convert texture to classifications
vert <- TT.vertices.tbl(class.sys = "USDA.TT")
vert$x <- 1-vert$SAND+(vert$SAND-(1-vert$SILT))*0.5
vert$y <- vert$CLAY*sin(pi/3)

USDA.TT <- data.frame(TT.classes.tbl(class.sys = "USDA.TT", collapse = ", "))
TT.pnt <- as.list(rep(NA, length(USDA.TT$name)))
poly.lst <- as.list(rep(NA, length(USDA.TT$name)))
for(i in 1:length(USDA.TT$name)){
TT.pnt[[i]] <- as.integer(strsplit(unclass(paste(USDA.TT)), ", ")[[1]])
poly.lst[[i]] <- vert],c("x","y")]
poly.lst[[i]] <- Polygons(list(Polygon(rbind(poly.lst[[i]], poly.lst[[i]]))), ID=i)
}

#convert texture triangle to a spatial object:
poly.sp <- SpatialPolygons(poly.lst, proj4string=CRS(as.character(NA)))
poly.USDA.TT <- SpatialPolygonsDataFrame(poly.sp, data.frame(ID=USDA.TT$name), match.ID=FALSE)
spplot(poly.USDA.TT)

#Load soil composition data
soil <- read.csv("soil.csv")
TT.plot(
class.sys = "HYPRES.TT",
tri.data = soil,
main = "Soil texture data"
)

TT.plot(class.sys = "none",
tri.data = soil,
z.name = "Organic Content",
main = "Soil texture triangle and Organic Content bubble plot"
)