[R] histograms resulting from call to soil.texture

Julien Moeys julien.moeys at mark.slu.se
Thu Oct 21 13:37:49 CEST 2010


Hi Eric

The package "soiltexture" has a function (TT.points.in.classes) 
to classify soil texture data according to various soil texture 
triangles. It is based on the function point.in.polygon() from 
the sp package.

See the example below, based on your example code. 

(The package has a rather comprehensive reference manual 
http://cran.r-project.org/web/packages/soiltexture/soiltexture.pdf)

all the best

Julien

### R code example (I have cut some rows out)

soil.dat<-read.table(textConnection(
"Field_Num Region Region_Num Region_Sym Region_Col Date Location Location_Num sand silt clay
1 US 1 1 4 6/3/1999 Surface 1 26.25 52.5 21.25
1 US 1 1 4 8/8/2000 Surface 1 27.5 52.5 20
1 US 1 1 4 8/8/2000 One_Foot 2 27.5 50 22.5
1 US 1 1 4 8/8/2000 Two_Foot 3 80 20 0
1 US 1 1 4 8/8/2000 Three_Foot 4 67.5 22.5 10
1 US 1 1 4 8/8/2000 Four_Foot 5 95 0 5
2 US 1 1 4 8/8/2000 Surface 1 55 12.5 32.5
2 US 1 1 4 6/4/2001 Surface 1 48.75 43.75 7.5
2 US 1 1 4 6/1/1999 Surface 1 28 34 38
2 US 1 1 4 8/8/2000 One_Foot 2 62.5 7.5 30
2 US 1 1 4 6/4/2001 One_Foot 2 65 16.25 18.75
2 US 1 1 4 8/8/2000 Two_Foot 3 55 0 45
2 US 1 1 4 6/4/2001 Two_Foot 3 50 21.25 28.75
2 US 1 1 4 8/8/2000 Three_Foot 4 47.5 5 47.5
2 US 1 1 4 6/4/2001 Three_Foot 4 77.5 15 7.5
2 US 1 1 4 8/8/2000 Four_Foot 5 62.5 0 37.5
2 US 1 1 4 6/4/2001 Four_Foot 5 75 15 10
5 US 1 1 4 8/1/2000 Surface 1 25 36.25 38.75
330 DS 19 0.5 2 6/8/2002 One_Foot 2 22.5 47.5 30
330 DS 19 0.5 2 8/8/2002 Two_Foot 3 26.25 51.25 22.5
330 DS 19 0.5 2 6/8/2002 Two_Foot 3 17.5 56.25 26.25
330 DS 19 0.5 2 8/8/2002 Three_Foot 4 21.25 56.25 22.5
330 DS 19 0.5 2 6/8/2002 Three_Foot 4 17.5 60 22.5
330 DS 19 0.5 2 8/8/2002 Four_Foot 5 22.5 52.5 25
330 DS 19 0.5 2 6/8/2002 Four_Foot 5 12.5 67.5 20
330 DS 19 0.5 2 8/8/2002 Six_Foot 6 31.25 55 13.75
330 DS 19 0.5 2 6/8/2002 Six_Foot 6 23.75 58.75 17.5"),header=T,sep="",dec=".")

closeAllConnections()
library(plotrix)
soil.texture(soil.dat[,c(9,10,11)],main='',show.lines=TRUE,show.names=TRUE,pch=soil.dat$Region_Num,cex=soil.dat$Region_Sym,col.names="grey10",col.lines="grey30",col.symbols=soil.dat$Region_Col)
legend(x=0.10,y=0.9,c("Upstream","Downstream"),pch=c(1,20),col=c("blue","red"),bty="o",bg="white",box.col="white")
title(main="Soil Texture",line=-1,cex=2.5)


### New code with soiltexture -------------------


install.packages("soiltexture") 
require("soiltexture")

# Texture plot
TT.plot( 
    tri.data  = soil.dat[,c("clay","silt","sand")], 
    class.sys = "USDA.TT", 
    css.names = c("clay","silt","sand"), 
    main      = "", 
    pch       = soil.dat$Region_Num, 
    cex       = soil.dat$Region_Sym, 
    col       = soil.dat$Region_Col 
)   #

# Returns a vector of charcater strings with 
# texture class abbreviation for each point
TT.points.in.classes(
    tri.data  = soil.dat[,c("clay","silt","sand")], 
    class.sys = "USDA.TT", 
    css.names = c("clay","silt","sand"), 
    PiC.type  = "t", 
)   #

# Set PiC.type to "l" for returning a table of logical
# or to "n" for returning a numerical 0, 1, 2 or 3 is 
# outputed (0 if the sample does not belong to a class, 
# 1 if it does, 2 if it lies on an edge and 3 if it lies 
# on a vertex)

# Returns a table of numerical with one column 
# per texture class and one row per texture point 
TT.points.in.classes(
    tri.data  = soil.dat[,c("clay","silt","sand")], 
    class.sys = "USDA.TT", 
    css.names = c("clay","silt","sand"), 
    PiC.type  = "n", 
)   #

### End of R code

-- 
-~-~-~-~-~-~
Julien MOEYS, post-doc researcher/Forskare
   Swedish University of Agricultural Sciences (SLU)
   Department of Soil and Environment
   Biogeophysics and water quality
   Ulls väg 17 ; box 7014
   750 07 Uppsala, Sweden
<http://www.slu.se/mark>
<http://julienmoeys.free.fr/>
-~-~-~-~-~-~

-----Original Message-----

Message: 119
Date: Wed, 20 Oct 2010 16:03:30 -0700 (PDT)
From: emorway <emorway at engr.colostate.edu>
To: r-help at r-project.org
Subject: [R] histograms resulting from call to soil.texture
Message-ID: <1287615810423-3004778.post at n4.nabble.com>
Content-Type: text/plain; charset=us-ascii


Hello,

Using the dataset below I produce a soil.texture plot (R code for this
included at the end).  One will notice I have plotted the points based on
whether or not they are in a region called 'upstream' or 'downstream'.  I'm
curious if there is a way to somehow extract counts of the number of points
(red points and blue points) falling within each classification (e.g. silty
loam, sandy clay, etc.)?

Eric

soil.dat<-read.table(textConnection("Field_Num Region Region_Num Region_Sym
Region_Col Date Location Location_Num sand silt clay
1 US 1 1 4 6/3/1999 Surface 1 26.25 52.5 21.25
1 US 1 1 4 8/8/2000 Surface 1 27.5 52.5 20
1 US 1 1 4 8/8/2000 One_Foot 2 27.5 50 22.5
1 US 1 1 4 8/8/2000 Two_Foot 3 80 20 0
1 US 1 1 4 8/8/2000 Three_Foot 4 67.5 22.5 10
1 US 1 1 4 8/8/2000 Four_Foot 5 95 0 5
2 US 1 1 4 8/8/2000 Surface 1 55 12.5 32.5
2 US 1 1 4 6/4/2001 Surface 1 48.75 43.75 7.5
2 US 1 1 4 6/1/1999 Surface 1 28 34 38
2 US 1 1 4 8/8/2000 One_Foot 2 62.5 7.5 30
2 US 1 1 4 6/4/2001 One_Foot 2 65 16.25 18.75
2 US 1 1 4 8/8/2000 Two_Foot 3 55 0 45
2 US 1 1 4 6/4/2001 Two_Foot 3 50 21.25 28.75
2 US 1 1 4 8/8/2000 Three_Foot 4 47.5 5 47.5
2 US 1 1 4 6/4/2001 Three_Foot 4 77.5 15 7.5
2 US 1 1 4 8/8/2000 Four_Foot 5 62.5 0 37.5
2 US 1 1 4 6/4/2001 Four_Foot 5 75 15 10
5 US 1 1 4 8/1/2000 Surface 1 25 36.25 38.75
330 DS 19 0.5 2 6/8/2002 One_Foot 2 22.5 47.5 30
330 DS 19 0.5 2 8/8/2002 Two_Foot 3 26.25 51.25 22.5
330 DS 19 0.5 2 6/8/2002 Two_Foot 3 17.5 56.25 26.25
330 DS 19 0.5 2 8/8/2002 Three_Foot 4 21.25 56.25 22.5
330 DS 19 0.5 2 6/8/2002 Three_Foot 4 17.5 60 22.5
330 DS 19 0.5 2 8/8/2002 Four_Foot 5 22.5 52.5 25
330 DS 19 0.5 2 6/8/2002 Four_Foot 5 12.5 67.5 20
330 DS 19 0.5 2 8/8/2002 Six_Foot 6 31.25 55 13.75
330 DS 19 0.5 2 6/8/2002 Six_Foot 6 23.75 58.75 17.5"),header=T)
closeAllConnections()
library(plotrix)
soil.texture(soil.dat[,c(9,10,11)],main='',show.lines=TRUE,show.names=TRUE,pch=soil.dat$Region_Num,cex=soil.dat$Region_Sym,col.names="grey10",col.lines="grey30",col.symbols=soil.dat$Region_Col)
legend(x=0.10,y=0.9,c("Upstream","Downstream"),pch=c(1,20),col=c("blue","red"),bty="o",bg="white",box.col="white")
title(main="Soil Texture",line=-1,cex=2.5)

-- 
View this message in context: http://r.789695.n4.nabble.com/histograms-resulting-from-call-to-soil-texture-tp3004778p3004778.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list