Legend that is big?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Legend that is big?

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

 

Thank you.

 

Kevin

 


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Legend that is big?

John Kane-2
Try something like this:

legend('bottom', leg.txt, horiz = TRUE, cex=.75)

A workable example is requested and would have been helpful.


----- Original Message -----
From: Kevin Burton <[hidden email]>
To: [hidden email]
Cc:
Sent: Saturday, January 21, 2012 8:47:36 AM
Subject: [R] Legend that is big?

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



Thank you.



Kevin




    [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Legend that is big?

Uwe Ligges-3
In reply to this post by rkevinburton


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]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Legend that is big?

rkevinburton
In reply to this post by John Kane-2
Just any plot but put say 100 items in the legend. If you include text with each item it clearly will not fit on any plot. So one workable example would be to add a legend with a 100 or more items to your plot of choice.

Thanks for the suggestion.

On Jan 21, 2012, at 10:14 AM, John Kane <[hidden email]> wrote:

> Try something like this:
>
> legend('bottom', leg.txt, horiz = TRUE, cex=.75)
>
> A workable example is requested and would have been helpful.
>
>
> ----- Original Message -----
> From: Kevin Burton <[hidden email]>
> To: [hidden email]
> Cc:
> Sent: Saturday, January 21, 2012 8:47:36 AM
> Subject: [R] Legend that is big?
>
> 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. 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.
>
>
>
> Thank you.
>
>
>
> Kevin
>
>
>
>
>     [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Legend that is big?

rkevinburton
In reply to this post by Uwe Ligges-3
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 <[hidden email]> 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]]
>>
>> ______________________________________________
>> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Legend that is big?

Jim Lemon
On 01/22/2012 06:56 AM, Kevin Burton wrote:
> 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?

Hi Kevin,
It sounds like you want something like color.legend (plotrix) that draws
a rectangle with as many colors as you like. However 100 colors would
probably require a legend as big as one side of the plot, and you
certainly couldn't get 100 readable labels on it. More like 10.

Jim

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Legend that is big?

rkevinburton
Thanks for the tip. I will try it out. I am more after a legend of colors than readable labels. In fact I would prefer getting rid of the text labels altogether.

On Jan 22, 2012, at 12:46 AM, Jim Lemon <[hidden email]> wrote:

> On 01/22/2012 06:56 AM, Kevin Burton wrote:
>> 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?
>
> Hi Kevin,
> It sounds like you want something like color.legend (plotrix) that draws a rectangle with as many colors as you like. However 100 colors would probably require a legend as big as one side of the plot, and you certainly couldn't get 100 readable labels on it. More like 10.
>
> Jim
>

______________________________________________
[hidden email] 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.