[R] specify size of box around legend

Duncan Murdoch murdoch.duncan at gmail.com
Fri Mar 11 16:15:06 CET 2016


On 11/03/2016 9:50 AM, Rainer M Krug wrote:
> Duncan Murdoch <murdoch.duncan at gmail.com> writes:
>
> > On 11/03/2016 9:01 AM, Rainer M Krug wrote:
> >> Hi
> >>
> >> assume the following code:
> >>
> >> --8<---------------cut here---------------start------------->8---
> >> plot(1,1)
> >> legend(x="topleft", legend = LETTERS[1:10], title = "L 1")
> >> legend(x="bottomleft", legend = paste(LETTERS[1:10], letters[1:12],LETTERS[1:10]), title = "L 2")
> >> legend(x="topright", legend = LETTERS[1:15], title = "L 3")
> >> --8<---------------cut here---------------end--------------->8---
> >>
> >> The box around L 1 is less wide than the box around L 2 due to automatic
> >> sizing of the box.
> >>
> >> Is there a way of specifying the width of the box, so that L 1 and L 2
> >> have the same width?
> >
> > text.width should work.  (It is in the ?legend help page, along with
> > approximately one million other optional arguments.)
>
> Thanks - that works.
>
> May I suggest to change the documentation from:
>
> --8<---------------cut here---------------start------------->8---
> text.width: the width of the legend text in x (‘"user"’) coordinates.
>            (Should be positive even for a reversed x axis.)  Defaults to
>            the proper value computed by ‘strwidth(legend)’.
> --8<---------------cut here---------------end--------------->8---
>
> to
>
> --8<---------------cut here---------------start------------->8---
> text.width: the width of the legend text in x (‘"user"’) coordinates.
>            (Should be positive even for a reversed x axis.)  If set,
>           it is used to compute the width of the legend box. Defaults to
>            the proper value computed by ‘strwidth(legend)’.
> --8<---------------cut here---------------end--------------->8---
>
> to make this clear?

I think it's already clear, but if not, this conversation is now in the 
public record, so anyone searching for "width of the legend box" on 
Google should find the help they need soon enough.
>
>
> >>
> >> In the same sense: can I also specify the height of the legend, so that
> >> L 1 and L 3 have the same height?
> >
> > You can add blank entries as fillers to L 1.
>
> True - but no other parameter to achieve this? Equivalent to text.widht?

I've only read the first hundred thousand argument descriptions, and I 
didn't find that.  You'll have to read the other nine hundred thousand 
yourself.

Duncan Murdoch



More information about the R-help mailing list