Re: [R] zero margin / marginless plots

From: Marc Schwartz <marc_schwartz_at_comcast.net>
Date: Thu 11 Jan 2007 - 03:36:33 GMT

On Wed, 2007-01-10 at 21:18 -0600, David Forrest wrote:
> Hi,
>
> I'd like to produce a marginless or zero margin plot so that the pixel
> coordinates represent the mathematics.
>
> xy<-data.frame(x=c(0,1,1,0,0),y=c(0,1,0,0,1))
> png('junk.png',width=300,height=300)
> par(mar=c(0,0,0,0))
> plot(xy$x,xy$y,xlim=c(0,1),ylim=c(,1))
> dev.off()
>
> The resultant file has about a 10 pixel margin around these lines, and I'm
> not sure what parameter or function is controlling this offset. Any
> hints?
>
> Thanks for your time,
> Dave

By default, the axis ranges are extended by +/- 4%. You can change this by using:

  plot(xy$x, xy$y, xlim = c(0, 1), ylim = c(0, 1),

       xaxs = "i", yaxs = "i")

where 'xaxs' and 'yaxs' set the axis ranges to the actual data ranges.

See ?par for more information.

HTH, Marc Schwartz



R-help@stat.math.ethz.ch mailing list
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. Received on Thu Jan 11 14:41:29 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 11 Jan 2007 - 16:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.