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

Peter Ehlers ehlers at ucalgary.ca
Tue Apr 17 00:52:44 CEST 2012


On 2012-04-16 14:53, 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.

Well, it can seem a bit daunting, but there really aren't all that
many parameters and they're bunched in a logical way. I recall that,
way back in the early days of R (for me), when I was still trying
to convince colleagues that R was the real thing (thank you Ross and
Robert and, of course, those indefatigable R-core folks), I spent a
couple of weeks in Newfoundland, Canada's most beautiful province, and
while others were photographing icebergs, I was desperately trying to
complete a consulting project that required a bit of fiddling with
lattice parameters to produce the kind of plots that were wanted for
the final report. It wasn't hard to figure out that lattice.heights
was a list of height parameters and that things like xlab.key.padding
affected the spacing between the xlab and the key. That's the beauty
of R's interactive nature - it's easy to experiment.

Peter Ehlers

>
> Jun
>
> On Mon, Apr 16, 2012 at 4:29 PM, Peter Ehlers <ehlers at ucalgary.ca
> <mailto: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 <mailto:R-help at r-project.org> mailing list
>             https://stat.ethz.ch/mailman/__listinfo/r-help
>             <https://stat.ethz.ch/mailman/listinfo/r-help>
>             PLEASE do read the posting guide
>             http://www.R-project.org/__posting-guide.html
>             <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 <mailto:R-help at r-project.org> mailing list
>         https://stat.ethz.ch/mailman/__listinfo/r-help
>         <https://stat.ethz.ch/mailman/listinfo/r-help>
>         PLEASE do read the posting guide
>         http://www.R-project.org/__posting-guide.html
>         <http://www.R-project.org/posting-guide.html>
>         and provide commented, minimal, self-contained, reproducible code.
>
>
>



More information about the R-help mailing list