[R] Problem w/ axis and distortion in a plotting function

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Wed Apr 17 19:09:43 CEST 2002


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list