[R] Question on spacing around plot and box in lattice

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Apr 4 00:11:37 CEST 2008


On 4/3/08, Saptarshi Guha <saptarshi.guha at gmail.com> wrote:
> Hello,
>         How can i increase the padding between the axis and the data
>  region(box just containing the figure) in xyplot?
>
>         An example:
>         new <- function(x){ if(x<0){ return(x^2) }else{ return(x) } }
>         x <- seq(-1,1,length.out=100)
>         y <- sapply(x,new)
>         sc=list()
>         sc$alternating=0
>         sc$tck=0
>
>         xyplot(y~x,type='l',
>                aspect=0.05,
>                scales=sc,
>                col='black',
>                xlab='',
>                ylab=''
>         )
>         When plotted on quartz(Mac) device, there is very little padding
>  between the bottom of the curve and the lower horizontal axis and
>  between the maximum values of the curve and the upper horizontal axis.
>         How can i increase the padding  - top,bottom,left and right?

The default padding is taken from lattice.getOption("axis.padding"),
and you could change it to, say, 20% using

xyplot(y~x,aspect=0.05,scales=sc,
       lattice.options = list(axis.padding = list(numeric = 0.2)))

For finer control, write your own prepanel function.

-Deepayan



More information about the R-help mailing list