Moffet, Corey
2002-Apr-17 14:24 UTC
[R] Problem w/ axis and distortion in a plotting function
I have a function for plotting soil texture that I am having a problem with. The function is: plot.psd <- function(sand, clay, ...) { conv.ter <- function(x, y) { x.con <- 100 - x - y*cos(1/3*pi) y.con <- y*sin(1/3*pi) data.frame(x=x.con, y=y.con) } plot(conv.ter(sand, clay), xlim = c(0,100), ylim = c(0,100*sin(1/3*pi)), axes = FALSE, xlab="", ylab="", ...) lines(conv.ter(c(100,0), c(0,100))) lines(conv.ter(c(100,0), c(0,0))) lines(conv.ter(c(0,0), c(0,100))) lines(conv.ter(c(85,90), c(0,10))) lines(conv.ter(c(70,85), c(0,15))) lines(conv.ter(c(50,43,52,52,80), c(0,7,7,20,20))) lines(conv.ter(c(43,23,45,52), c(7,27,27,20))) lines(conv.ter(c(45,45,65), c(27,35,35))) lines(conv.ter(c(45,45), c(35,55))) lines(conv.ter(c(45,20,20,23), c(40,40,27,27))) lines(conv.ter(c(20,0), c(40,60))) lines(conv.ter(c(20,0), c(27,27))) lines(conv.ter(c(20,0), c(40,40))) lines(conv.ter(c(0,8,20), c(12,12,0))) for(i in seq(10, 90, 10)) { lines(conv.ter(c(i,i), c(0,(100-i))), lty = 3) lines(conv.ter(c((100-i),0), c(i,i)), lty = 3) lines(conv.ter(c(i,0), c(0,i)), lty = 3) } text(conv.ter(c(50, 60, -10), c(-10, 55, 55) ), c("Sand", "Clay", "Silt"), cex = 0.9 ) text(conv.ter(c(0,20,40,60,80,100 ), c(rep(-2, 6)) ), c("0", "20", "40", "60", "80", "100"), cex = 0.75 ) text(conv.ter(c(103,83,63,43,23,3 ), c(0,20,40,60,80,100) ), c("0", "20", "40", "60", "80", "100"), cex = 0.75 ) text(conv.ter(c(rep(-3,6)), c(102,82,62,42,22,2)), c("0", "20", "40", "60", "80", "100"), cex = 0.75 ) } The label for the Sand axis (first text line above) is not shown. The second problem I have with this is that the triangle should be equilateral but when I print it the triangle is not. If I use par(pty = "s") before the plot.psd call than the triangle is always stretched vertically. Any Ideas? With best wishes and kind regards I am Sincerely, Corey A. Moffet Instructor Department of Range, Wildlife, and Fisheries Management Mail Stop 2125 Texas Tech University Lubbock, Texas 79409-2125 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Martin Maechler
2002-Apr-17 15:30 UTC
[R] Problem w/ axis and distortion in a plotting function
Hi Corey,>>>>> "CoMo" == Moffet, Corey <Corey.Moffet at ttu.edu> writes:CoMo> I have a function for plotting soil texture that I am CoMo> having a problem with. The function is: ........... (it would be helpful if together with the function, you'd give an example call that we can use as well, i.e., with "R builtin" or random (sand <- rnorm(...)) data, so we can easily see what you mean) CoMo> The label for the Sand axis (first text line above) is CoMo> not shown. you have an explicit xlab = "" -- so why would you expect a label? CoMo> The second problem I have with this is that the CoMo> triangle should be equilateral but when I print it the CoMo> triangle is not. If I use par(pty = "s") before the CoMo> plot.psd call than the triangle is always stretched CoMo> vertically. plot(...., asp = 1 ) ## !!! This is found (only?) on help(plot.default), a very nice feature and probably much under-used possibility for specifying and fixing the ASPect ratio. Does it help? Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Moffet, Corey
2002-Apr-17 16:51 UTC
[R] Problem w/ axis and distortion in a plotting function
Thank you for your quick response. Using asp = 1 fixed 1 problem but I still have the problem with labeling the sand axis. I have made some changes to the function so I will include it again and give an example call: plot.psd <- function(sand, clay, ...) { conv.ter <- function(x, y) { x.con <- 100 - x - y*cos(1/3*pi) y.con <- y*sin(1/3*pi) data.frame(x=x.con, y=y.con) } plot(conv.ter(sand, clay), xlim = c(0,100), ylim = c(0,100*sin(1/3*pi)), axes = FALSE, xlab="", ylab="", asp = 1, ...) lines(conv.ter(c(100,0), c(0,100))) lines(conv.ter(c(100,0), c(0,0))) lines(conv.ter(c(0,0), c(0,100))) lines(conv.ter(c(85,90), c(0,10))) lines(conv.ter(c(70,85), c(0,15))) lines(conv.ter(c(50,43,52,52,80), c(0,7,7,20,20))) lines(conv.ter(c(43,23,45,52), c(7,27,27,20))) lines(conv.ter(c(45,45,65), c(27,35,35))) lines(conv.ter(c(45,45), c(35,55))) lines(conv.ter(c(45,20,20,23), c(40,40,27,27))) lines(conv.ter(c(20,0), c(40,60))) lines(conv.ter(c(20,0), c(27,27))) lines(conv.ter(c(20,0), c(40,40))) lines(conv.ter(c(0,8,20), c(12,12,0))) for(i in seq(10, 90, 10)) { lines(conv.ter(c(i,i), c(0,(100-i))), lty = 3) lines(conv.ter(c((100-i),0), c(i,i)), lty = 3) lines(conv.ter(c(i,0), c(0,i)), lty = 3) } text(conv.ter(c(53, 58, -10), c(-7, 55, 55) ), c("Sand", "Clay", "Silt"), cex = 0.9 ) text(conv.ter(c(20,40,60,80,100 ), c(rep(-2, 5)) ), c("20", "40", "60", "80", "100"), cex = 0.75 ) text(conv.ter(c(83,63,43,23,3 ), c(20,40,60,80,100) ), c("20", "40", "60", "80", "100"), cex = 0.75 ) text(conv.ter(c(rep(-3,5)), c(82,62,42,22,2)), c("20", "40", "60", "80", "100"), cex = 0.75 ) } plot.psd(c(33,43,53), c(33,23,13), pch = c("1", "2", "3"), col = c("blue", "black", "red"), cex = 0.5) What I am trying to do is replace the default x-axis with a custom axis but Sand is obscured from view in the R Graphics Device window. I have used axes = FALSE, xlab="", ylab="" to clear the defaults and the four text calls at the bottom of the function are trying to replace the blank defaults with my custom axis. What am I missing? With best wishes and kind regards I am Sincerely, Corey A. Moffet Instructor Department of Range, Wildlife, and Fisheries Management Mail Stop 2125 Texas Tech University Lubbock, Texas 79409-2125 -----Original Message----- From: Martin Maechler [mailto:maechler at stat.math.ethz.ch] Sent: Wednesday, April 17, 2002 10:30 AM To: Moffet, Corey Cc: R-Help (E-mail) Subject: Re: [R] Problem w/ axis and distortion in a plotting function Hi Corey,>>>>> "CoMo" == Moffet, Corey <Corey.Moffet at ttu.edu> writes:CoMo> I have a function for plotting soil texture that I am CoMo> having a problem with. The function is: ........... (it would be helpful if together with the function, you'd give an example call that we can use as well, i.e., with "R builtin" or random (sand <- rnorm(...)) data, so we can easily see what you mean) CoMo> The label for the Sand axis (first text line above) is CoMo> not shown. you have an explicit xlab = "" -- so why would you expect a label? CoMo> The second problem I have with this is that the CoMo> triangle should be equilateral but when I print it the CoMo> triangle is not. If I use par(pty = "s") before the CoMo> plot.psd call than the triangle is always stretched CoMo> vertically. plot(...., asp = 1 ) ## !!! This is found (only?) on help(plot.default), a very nice feature and probably much under-used possibility for specifying and fixing the ASPect ratio. Does it help? Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
ripley@stats.ox.ac.uk
2002-Apr-17 17:09 UTC
[R] Problem w/ axis and distortion in a plotting function
On Wed, 17 Apr 2002, Moffet, Corey wrote:> Thank you for your quick response. Using asp = 1 fixed 1 problem but I > still have the problem with labeling the sand axis. I have made some > changes to the function so I will include it again and give an example call: > > plot.psd <- function(sand, clay, ...) { > conv.ter <- function(x, y) { > x.con <- 100 - x - y*cos(1/3*pi) > y.con <- y*sin(1/3*pi) > data.frame(x=x.con, y=y.con) > } > plot(conv.ter(sand, clay), xlim = c(0,100), ylim = c(0,100*sin(1/3*pi)), > axes = FALSE, xlab="", ylab="", asp = 1, ...) > lines(conv.ter(c(100,0), c(0,100))) > lines(conv.ter(c(100,0), c(0,0))) > lines(conv.ter(c(0,0), c(0,100))) > lines(conv.ter(c(85,90), c(0,10))) > lines(conv.ter(c(70,85), c(0,15))) > lines(conv.ter(c(50,43,52,52,80), c(0,7,7,20,20))) > lines(conv.ter(c(43,23,45,52), c(7,27,27,20))) > lines(conv.ter(c(45,45,65), c(27,35,35))) > lines(conv.ter(c(45,45), c(35,55))) > lines(conv.ter(c(45,20,20,23), c(40,40,27,27))) > lines(conv.ter(c(20,0), c(40,60))) > lines(conv.ter(c(20,0), c(27,27))) > lines(conv.ter(c(20,0), c(40,40))) > lines(conv.ter(c(0,8,20), c(12,12,0))) > for(i in seq(10, 90, 10)) { > lines(conv.ter(c(i,i), c(0,(100-i))), lty = 3) > lines(conv.ter(c((100-i),0), c(i,i)), lty = 3) > lines(conv.ter(c(i,0), c(0,i)), lty = 3) > } > text(conv.ter(c(53, 58, -10), c(-7, 55, 55) ), c("Sand", "Clay", "Silt"), > cex = 0.9 ) > text(conv.ter(c(20,40,60,80,100 ), c(rep(-2, 5)) ), c("20", "40", "60", > "80", "100"), cex = 0.75 ) > text(conv.ter(c(83,63,43,23,3 ), c(20,40,60,80,100) ), c("20", "40", "60", > "80", "100"), cex = 0.75 ) > text(conv.ter(c(rep(-3,5)), c(82,62,42,22,2)), c("20", "40", "60", "80", > "100"), cex = 0.75 ) > } > > plot.psd(c(33,43,53), c(33,23,13), pch = c("1", "2", "3"), col = c("blue", > "black", "red"), cex = 0.5) > > > What I am trying to do is replace the default x-axis with a custom axis but > Sand is obscured from view in the R Graphics Device window. I have used > axes = FALSE, xlab="", ylab="" to clear the defaults and the four text calls > at the bottom of the function are trying to replace the blank defaults with > my custom axis. What am I missing?xpd=TRUE. text is not designed for the margins: that is what mtext is used for, so you need text(conv.ter(c(53, 58, -10), c(-7, 55, 55) ), c("Sand", "Clay", "Silt"), cex = 0.9, xpd = TRUE ) to avoid clipping to the plot region. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Moffet, Corey
2002-Apr-17 17:20 UTC
[R] Problem w/ axis and distortion in a plotting function
Thank you both. These suggestions fixed my problem. I added asp = 1 to the plot call in the function to keep the triangle equilateral, and xpd = TRUE in the first text call in the function. With best wishes and kind regards I am Sincerely, Corey A. Moffet Instructor Department of Range, Wildlife, and Fisheries Management Mail Stop 2125 Texas Tech University Lubbock, Texas 79409-2125 -----Original Message----- From: ripley at stats.ox.ac.uk [mailto:ripley at stats.ox.ac.uk] Sent: Wednesday, April 17, 2002 12:10 PM To: Moffet, Corey Cc: 'Martin Maechler'; R-Help (E-mail) Subject: RE: [R] Problem w/ axis and distortion in a plotting function On Wed, 17 Apr 2002, Moffet, Corey wrote:> Thank you for your quick response. Using asp = 1 fixed 1 problem but I > still have the problem with labeling the sand axis. I have made some > changes to the function so I will include it again and give an examplecall:> > plot.psd <- function(sand, clay, ...) { > conv.ter <- function(x, y) { > x.con <- 100 - x - y*cos(1/3*pi) > y.con <- y*sin(1/3*pi) > data.frame(x=x.con, y=y.con) > } > plot(conv.ter(sand, clay), xlim = c(0,100), ylim = c(0,100*sin(1/3*pi)), > axes = FALSE, xlab="", ylab="", asp = 1, ...) > lines(conv.ter(c(100,0), c(0,100))) > lines(conv.ter(c(100,0), c(0,0))) > lines(conv.ter(c(0,0), c(0,100))) > lines(conv.ter(c(85,90), c(0,10))) > lines(conv.ter(c(70,85), c(0,15))) > lines(conv.ter(c(50,43,52,52,80), c(0,7,7,20,20))) > lines(conv.ter(c(43,23,45,52), c(7,27,27,20))) > lines(conv.ter(c(45,45,65), c(27,35,35))) > lines(conv.ter(c(45,45), c(35,55))) > lines(conv.ter(c(45,20,20,23), c(40,40,27,27))) > lines(conv.ter(c(20,0), c(40,60))) > lines(conv.ter(c(20,0), c(27,27))) > lines(conv.ter(c(20,0), c(40,40))) > lines(conv.ter(c(0,8,20), c(12,12,0))) > for(i in seq(10, 90, 10)) { > lines(conv.ter(c(i,i), c(0,(100-i))), lty = 3) > lines(conv.ter(c((100-i),0), c(i,i)), lty = 3) > lines(conv.ter(c(i,0), c(0,i)), lty = 3) > } > text(conv.ter(c(53, 58, -10), c(-7, 55, 55) ), c("Sand", "Clay","Silt"),> cex = 0.9 ) > text(conv.ter(c(20,40,60,80,100 ), c(rep(-2, 5)) ), c("20", "40", "60", > "80", "100"), cex = 0.75 ) > text(conv.ter(c(83,63,43,23,3 ), c(20,40,60,80,100) ), c("20", "40","60",> "80", "100"), cex = 0.75 ) > text(conv.ter(c(rep(-3,5)), c(82,62,42,22,2)), c("20", "40", "60", "80", > "100"), cex = 0.75 ) > } > > plot.psd(c(33,43,53), c(33,23,13), pch = c("1", "2", "3"), col = c("blue", > "black", "red"), cex = 0.5) > > > What I am trying to do is replace the default x-axis with a custom axisbut> Sand is obscured from view in the R Graphics Device window. I have used > axes = FALSE, xlab="", ylab="" to clear the defaults and the four textcalls> at the bottom of the function are trying to replace the blank defaultswith> my custom axis. What am I missing?xpd=TRUE. text is not designed for the margins: that is what mtext is used for, so you need text(conv.ter(c(53, 58, -10), c(-7, 55, 55) ), c("Sand", "Clay", "Silt"), cex = 0.9, xpd = TRUE ) to avoid clipping to the plot region. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._