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.
On Wed, 2004-11-03 at 09:55, Dan Bolser wrote:> 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.Dan, Do not edit the barplot() code. Use the legend() function instead, which enables you to specify the x,y coordinates of the upper left hand corner of the legend box. See ?legend A fair number of the questions that you have had regarding graphics are covered in Chapter 12 "Graphical Procedures" in "An Introduction to R": http://cran.r-project.org/doc/manuals/R-intro.pdf which is included with the R installation. Another online resource for some graphics assistance would be R News Volume 3 Number 2 for October 2003, which has an article on R's base graphics in the R Help Desk section: http://cran.r-project.org/doc/Rnews/Rnews_2003-2.pdf Notwithstanding all of that, searching the r-help archives is yet another terrific online (and free) resource that you _should_ avail yourself of. HTH, Marc Schwartz
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? : In package gplots (in bundle gregmisc in R 2.0.0) there is smartlegend.
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).
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>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