[R] zero margin / marginless plots (in lattice?)

David Forrest drf5n at maplepark.com
Fri Jan 12 22:42:06 CET 2007


On Thu, 11 Jan 2007, David Forrest wrote:

> Thanks.  The xaxs|yaxs='i' works well for the base graphics.  Is there an
> additional parameter in play for lattice graphics?  The closest I could
> gotten is the below which still leaves a bit of a margin:
>
> xy<-data.frame(x=c(0,1,1,0,0),y=c(0,1,0,0,1))
> xyplot(y~x,xy,scales=list(axs='i',draw=FALSE),type='l',xlab=NULL,ylab=NULL)


>From an old email of Depayan's I see these margins in lattice are are due 
to 'padding' and this lattice theme seems to eliminate them:

theme.novpadding <-
   list(layout.heights =
        list(top.padding = 0,
 	    main.key.padding = 0,
 	    key.axis.padding = 0,
 	    axis.xlab.padding = 0,
 	    xlab.key.padding = 0,
 	    key.sub.padding = 0,
 	    bottom.padding = 0),
        layout.widths =
        list(left.padding = 0,
 	    key.ylab.padding = 0,
 	    ylab.axis.padding = 0,
 	    axis.key.padding = 0,
 	    right.padding = 0))


Then, using the quakes data example from ?xyplot :

library(stats)
xyplot(lat~long,quakes,
   scales=list(axs='i',draw=FALSE),
   ,xlab=NULL,ylab=NULL,par.settings = theme.novpadding)


...Then this graphic should drop nicely into GoogleEarth with a 
boundingbox matching the data:

range(quakes$lat);range(quakes$long)
[1] -38.59 -10.72
[1] 165.67 188.13

dev.copy(png,width=400,height=400,file='quakes.png')

and post it to the web and KMZ file as at:

http://www.maplepark.com/drf5n/extras/R_xyplot_googleEarth.kmz

Thanks.

>
> Dave
>
> On Wed, 10 Jan 2007, Marc Schwartz wrote:
>
>> 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 at 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.
>>
>
>

-- 
  Dr. David Forrest
  drf at vims.edu                                    (804)684-7900w
  drf5n at maplepark.com                             (804)642-0662h
                                    http://maplepark.com/~drf5n/



More information about the R-help mailing list