[R] Results Differ in Ternary Plot Matrix of Compositional Response Variables
Rich Shepard
rshepard at appl-ecosys.com
Thu Apr 30 22:56:47 CEST 2015
After hours of looking for the reason why one data set plots correctly and
another one does not I am still not seeing the reason. The only differences
I see between the two data sets is the number of discrete variables (one has
6 years, the other 7 years) and one contains zeros. I wonder if the number
of discrete variables is the issue.
I'm sure that more experienced eyes will see the reason for the different
results and will point it out to me.
The following data and code produce a matrix of ternary plots with the
other continuous variables represented by a dot above the top point of the
triangle:
<filename = snow-regression.dat>
"Year","NO3","SO4","pH","Fi","Ga","Gr","Pr","Sh"
"2005",0.60,816,7.87,0.0556,0.5370,0.1667,0.1667,0.0741
"2006",0.40,224,7.59,0.0435,0.6739,0.0870,0.1522,0.0435
"2010",0.10,571,7.81,0.0735,0.4706,0.1029,0.1912,0.1618
"2011",0.52,130,7.42,0.0462,0.5692,0.0769,0.2462,0.0615
"2012",0.42,363,7.79,0.0548,0.5205,0.0548,0.2466,0.1233
"2013",0.42,363,7.79,0.0484,0.5323,0.1129,0.2419,0.0645
<snow-ternary-plot.R>
# Create matrix of ternary plots of FFGs as dependent variables.
# Follows 'Analyzing Compositional Data with R' sec. 5.3; pp 122 ff
# Change stream name as necessary.
# load package from library
require(compositions)
# read in raw data
SnowRegr <- read.csv('snow-regression.dat', header=T)
# extract response variables
SnowY <- acomp(SnowRegr[,5:9])
# column headings; variables
names(SnowRegr)
# continuous explanatory co-variables
SnowCovars <- SnowRegr[,c("Year","NO3","SO4","pH")]
# first continuous co-variable
SnowX1 <- SnowCovars$NO3
# second continuous co-variable
SnowX2 <- SnowCovars$SO4
# third continuous co-variable
SnowX3 <- SnowCovars$pH
# discrete co-variable
SnowX4 <-
factor(SnowCovars$Year,c("2005","2006","2010","2011","2012","2013"),ordered=T)
# for the discrete co-var, ANOVA not specified in unique way so contrasts must
be specified; use the
# treatment contrasts.
contrasts(SnowX4) <- "contr.treatment"
# save figure parameters
opar <- par(xpd=NA,no.readonly=T)
# ternary plot matrix
plot(SnowY, pch=as.numeric(SnowX4), col=c("red","dark green","dark blue","dark
goldenrod","dark orange","dark grey")[SnowX4])
# add legend
legend(x=0.83, y=-0.165, abbreviate(levels(SnowX4),
minlength=1),pch=as.numeric(SnowX4), col=c("red","dark green","dark blue","dark
goldenrod","dark orange","dark grey"), ncol=2, xpd=T, bty="n", yjust=0)
# reset plot parameters
par(opar)
# unload the package
detach('package:compositions')
This data set with eqivalent code produces plots with the other continuous
variables as bars with colors on the top points of the triangles:
<filename = jerritt-regression.dat>
"Year","NO3","SO4","pH","Fi","Ga","Gr","Pr","Sh"
"2004",1.70,2200,8.70,0.0444,0.6889,0.0222,0.2222,0.0222
"2005",2.50,5000,8.43,0.0182,0.5636,0.0909,0.3091,0.0182
"2006",1.80,6670,8.57,0.0370,0.6173,0.0741,0.2469,0.0247
"2010",0.54,4000,8.00,0.0870,0.6087,0.0870,0.2174,0.0000
"2011",2.70,4300,8.47,0.0449,0.5256,0.0897,0.2949,0.0449
"2012",0.76,595,8.21,0.0000,0.4231,0.0769,0.5000,0.0000
"2013",0.76,595,8.21,0.0000,0.4545,0.0455,0.4545,0.0455
<jerritt-ternary-plot.R>
# Create matrix of ternary plots of FFGs as dependent variables.
# Follows 'Analyzing Compositional Data with R' sec. 5.3; pp 122 ff
# Change stream name as necessary.
# load package from library
require(compositions)
# read in raw data
JerrittRegr <- read.csv('jerritt-regression.dat', header=T)
# extract response variables
JerrittY <- acomp(JerrittRegr[,5:9])
# column headings; variables
names(JerrittRegr)
# continuous explanatory co-variables
JerrittCovars <- JerrittRegr[,c("Year","NO3","SO4","pH")]
# first continuous co-variable
JerrittX1 <- JerrittCovars$NO3
# second continuous co-variable
JerrittX2 <- JerrittCovars$SO4
# third continuous co-variable
JerrittX3 <- JerrittCovars$pH
# discrete co-variable
JerrittX4 <-
factor(JerrittCovars$Year,c("2004","2005","2006","2010","2011","2012","2013"),ordered=T)
# for the discrete co-var, ANOVA not specified in unique way so contrasts must
be specified; use the
# treatment contrasts.
contrasts(JerrittX4) <- "contr.treatment"
# save figure parameters
opar <- par(xpd=NA,no.readonly=T)
# ternary plot matrix
plot(JerrittY, pch=as.numeric(JerrittX4), col=c("black","red","dark
green","dark blue","dark goldenrod","dark orange","dark grey")[JerrittX4])
# add legend
legend(x=0.83, y=-0.165, abbreviate(levels(JerrittX4),
minlength=1),pch=as.numeric(JerrittX4), col=c("black","red","dark green","dark
blue","dark goldenrod","dark orange","dark grey"), ncol=2, xpd=T, bty="n",
yjust=0)
# reset plot parameters
par(opar)
# unload the package
detach('package:compositions')
Thanks in advance,
Rich
More information about the R-help
mailing list