[R] How to adjust the distance between legend and the plot (xyplot)

David Winsemius dwinsemius at comcast.net
Tue Apr 17 00:11:31 CEST 2012


On Apr 16, 2012, at 5:53 PM, Jun Shen wrote:

> Hi, Peter,
>
> Thanks. This is exactly what I am looking for! Just a little  
> concern. Since there are so many parameters in the trellis.par, how  
> do we even know there is one that can do what we want? The  
> documentation does not really have that much details.
>
> Jun

The "Lattice" book helps, especially the table on page 127. You can  
also use:

names( trellis.par.get() )

names( trellis.par.get("layout.heights") )

The material Peter mentions has a more expanded discussion on page  
129-130. Sometimes you can get further help with Murrell's 'R Graphics'.

>
> On Mon, Apr 16, 2012 at 4:29 PM, Peter Ehlers <ehlers at ucalgary.ca>  
> wrote:
> On 2012-04-16 08:51, David Winsemius wrote:
>
> On Apr 16, 2012, at 11:43 AM, Jun Shen wrote:
>
> Dear list,
>
> As the title indicates if I draw the legend outside of the plot, how
> do I
> adjust the distance between the legend and the plot? The default
> setting is
> too close. Thanks.
>
>   From the help page:
>
> "just
> A character or numeric vector of length one or two giving horizontal
> and vertical justification for the placement of the legend. See
> grid.layout for more precise details."
>
>
>
> I would have a look at the layout.heights trellis parameters and set
> these to suit - in this case probably just the xlab.key.padding value.
>
> Look at the list of parameters with
>
>  trellis.par.get("layout.heights")
>
> # (or wrap this in str() for a briefer output).
>
> Then include a par.settings argument in the xyplot call:
>
>  xyplot( 1 ~ 1,
>         par.settings = list( layout.heights = list(
>              xlab.key.padding = 5 )),
>         key = list( .... etc
>
>
> Peter Ehlers
>
>
>
>
>
>
> Here is the sample code I have
>
> ==========================================================
> xyplot
> (1~1,key=list(space='bottom',columns=2,text=list(c('a','b','c','d')),
> lines
> =list(lwd=2,pch=c(1,1,2,2),cex=1.2,col=c(1,2,3,4),type=c('p','l')))
> )
>
> Jun
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> R-help at r-project.org 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.
>
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list