[R] Legend that is big?

Kevin Burton rkevinburton at charter.net
Sat Jan 21 20:56:25 CET 2012


Of course by entering 'blah' you just get a legend of one value. I guess I would like to remove the text altogether and put the colored boxes (or circles) right next to each other. This would form sort of a gradient. So say I needed a legend for 100 colored values on the plot. The colors are generated by:
colors <- rainbow(100)
How would I make such a legend?
Thanks for the suggestions. They are tricks definitely worth knowing.

On Jan 21, 2012, at 10:16 AM, Uwe Ligges <ligges at statistik.tu-dortmund.de> wrote:

> 
> 
> 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