Rich Shepard
2015-Apr-30 20:56 UTC
[R] Results Differ in Ternary Plot Matrix of Compositional Response Variables
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
David L Carlson
2015-May-01 15:54 UTC
[R] Results Differ in Ternary Plot Matrix of Compositional Response Variables
Add plotMissings=FALSE to the second plot and see the plot.acomp manual page description of this argument: plot(JerrittY, pch=as.numeric(JerrittX4), col=c("black","red", "dark green", "dark blue","dark goldenrod","dark orange","dark grey")[JerrittX4], plotMissings=FALSE) ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Rich Shepard Sent: Thursday, April 30, 2015 3:57 PM To: r-help at r-project.org Subject: [R] Results Differ in Ternary Plot Matrix of Compositional Response Variables 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 ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Rich Shepard
2015-May-01 18:32 UTC
[R] Results Differ in Ternary Plot Matrix of Compositional Response Variables
On Fri, 1 May 2015, David L Carlson wrote:> Add plotMissings=FALSE to the second plot and see the plot.acomp manual > page description of this argument: > > plot(JerrittY, pch=as.numeric(JerrittX4), col=c("black","red", "dark green", > "dark blue","dark goldenrod","dark orange","dark grey")[JerrittX4], > plotMissings=FALSE)David, Mea culpa! I overlooked the man page for plot.acomp. When I add plotMissings=FALSE I see no differences in the output despite there being zeros for a comple of variables in two years. The horizontal bar with colors and labels on top of each ternary diagram is what I want to eliminate and replace with the dot seen in plots with no more than 6 rows (years) of data. There are 3 data sets with 6 rows, 1 with 7 rows (jerritt), and one with 8 rows and no missing data. The latter two have the horizontal bars while the former three have dots. Thanks, Rich