[R] Legend that is big?

Uwe Ligges ligges at statistik.tu-dortmund.de
Sat Jan 21 17:16:12 CET 2012



On 21.01.2012 14:47, Kevin Burton wrote:
> I can put a legend on a plot with something like:
>
>
>
> legend('bottom', leg.txt, horiz = TRUE, fill = colors)
>
>
>
> But what if the arrays leg.txt and colors are too big? I would still like to
> provide a legend but to save space I would like to just show small boxes
> with the color filled in so it will still fit on the plot.

The trick could be to use filled points that look like boxes:

  legend('bottom', "blah", horiz = TRUE, pch = 15, col = colors, pt.cex 
= 0.5)


> If I could adjust
> the size of the boxes (at least in one dimension) that would be desirable.
> As a bonus and if there is room I would like to label the top and bottom
> (left and right) of the legend with text indicating a minimum and maximum. I
> am relatively new to 'R' and especially 'R' graphics so any help would be
> greatly appreciated.


If you save the returned value from legend() inn some object:

lg <- legend(......)
str(lg)

you will see that there is information about the soze and location of 
the legend that can be used to calculate positions for other text() 
around....

Uwe Ligges






>
>
> Thank you.
>
>
>
> Kevin
>
>
>
>
> 	[[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.



More information about the R-help mailing list