[R] Legend placement in barplot?
Dan Bolser
dmb at mrc-dunn.cam.ac.uk
Fri Nov 5 01:27:19 CET 2004
On Fri, 5 Nov 2004, F Z wrote:
>You can use locator() nested within legend()
>i.e.
>
>plot(YourVariable)
>legend(locator(1),legend="Your Legend")
>
>Once you call this command it will display "Your Legend" in the place where
>you left clicked your mouse. Beware that, as described in the documentation
>"...'locator' is only supported on screen devices such as 'X11','windows'
>and 'quartz'. On other devices the call will do nothing"
>
>
>Altrenativelly you can pass the exact coordinates of the position where you
>want the legend, instead of using locator
>i.e.
>
>plot(YourVariable)
>x<-list(x=-91.76781, y=46.87375)
>legend(x,legend="Your Legend")
>
>I hope that this helps
>
>Francisco
Thanks very much for the tips. Basically I want a very flexible solution
that lets me punch the numbers in - take a look at the result and then
immediatly dump a .ps / .eps / .png format of what I saw. The result
should be very quickly 'publication quality' (whatever that is).
The problem with locator is that I don't know how to make it work with
postscript, and I don't want to find out. I don't want to have to probe my
figure for the coordinates every time I change the data in my figure. I am
happy saying something like 'oh, top left is bad, lets use top right' -
done.
smartlegend is almost there, I just think barplot should support exactly
the same functionality as smartlegend. This would save me the hassle of
creating a new legend every time my data changes, matching up colors and
names.
I am sure their is a way to code this, but I don't want to write code - at
least not code that I have to look at when what I want to see is my data.
>
>>From: Gabor Grothendieck <ggrothendieck at myway.com>
>>To: r-help at stat.math.ethz.ch
>>Subject: Re: [R] Legend placement in barplot?
>>Date: Wed, 3 Nov 2004 18:48:48 +0000 (UTC)
>>
>>Dan Bolser <dmb <at> mrc-dunn.cam.ac.uk> writes:
>>
>>:
>>: This has been asked before, but all the answers are hidiously complex.
>>:
>>: The
>>:
>>: legend.text=TRUE
>>:
>>: option of barplot is almost exactly what I need, except I need a
>>:
>>: legend.placement='tl'
>>:
>>: (top left) option. This option would be in contrast to the default
>>: placement which we could call 'tr' (top right).
>>:
>>: Anyone know how to edit the barplot code to make this change? Could
>>: someone like me work out how to do this?
>>:
>>: Cheers,
>>: Dan.
>>
>>
>>Check out gplots::smartlegend (in the R 2.0.0 gregmisc bundle).
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide!
>>http://www.R-project.org/posting-guide.html
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list