[R] asp and ylim

Martin Maechler maechler at stat.math.ethz.ch
Mon Jul 21 15:54:51 CEST 2008


>>>>> "DE" == David Epstein <David.Epstein at warwick.ac.uk>
>>>>>     on Mon, 21 Jul 2008 14:32:47 +0100 writes:

    DE> A really great answer to my concerns! I'll get hold of the Paul  
    DE> Murrell book, and see how far I can get.

    DE> On 21 Jul, 2008, at 10:48, Martin Maechler wrote:
    >> Play around resizing your graphics window..
    >> 
    >> This is very instructive, with an 'asp = .' using "traditional
    >> graphics" plot().
    DE> OK, but I don't know what you mean by "asp=.". Does this mean setting  
    DE> asp equal to NULL, or to a default setting?

I meant  *any* value 
such as your example's  asp = 1

    DE> Perhaps the best solution is to live with plot() as it
    DE> is. If I need the picture for a paper, I will export
    DE> data to Matlab or Mathematica or Illustrator, where I
    DE> can get the control I want.

    >> Hah, you must be kidding!

    DE> Change "kidding" to "frustrated"!

well... ... your choice  :-)

    >> For a "paper plot", e.g.,  pdf() as I'd recommend nowadays,
    >> you can set the device region by 'width' and 'height' ;
    >> and if you really want to use "traditional graphics" here, do
    >> something like
    >> 
    >> ## modified by MM from David Epstein's original example
    >> myplot <- function(y, yb = mean(y), ylim = c(-1,1)) {
    >> ybarv <- rep.int(yb, length(y))
    >> x <- seq_along(y)
    >> plot(x,y, asp=1, xlab="position",ylab="ybar", type="n", ylim =  
    >> ylim)
    >> abline(h = ybar)## instead of  segments(x[1], ybar, x[ylength],  
    >> ybar)
    >> segments(x, ybarv, x,y)
    >> points  (x, ybarv, pch=21,  bg="white")
    >> points  (x, y,     pch=19, col="black")
    >> invisible()
    >> }
    >> 
    DE> I learned quite a few things from this code above.

    >> y <- c(1.21, 0.51, 0.14, 1.62, -0.8,
    >> 0.72, -1.71, 0.84, 0.02, -0.12)
    >> 
    >> myplot(y)

      ## MM: setting device region so that  ylim = c(-1,1)  "about fits"
      pdf.do("asp-ex.pdf", height= 3.3, width=10)
      myplot(y)
      pdf.end()

    DE> I cannot find the functions pdf.do and pdf.end. Are these part of  
    DE> some package that I need to load? Your package?

Oh, that's been an "accident" :
They are part of 'sfsmisc' (a small R-code only package you can
quickly install and load) and I use them all the time, 
but really, I've wanted to just use

 pdf("asp-ex.pdf", height= 3.3, width=10)
 myplot(y)
 ## and now view the pdf file in your favorite viewer

Martin

    DE> Thanks
    DE> David



More information about the R-help mailing list