Skip to content

Problem w/ axis and distortion in a plotting function

2 messages · Moffet, Corey, Martin Maechler

#
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hi Corey,
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._