I'm trying to automate making a bunch of figures and I need a way to automate legend position. As I understand it the legend is placed based on coordinates. I don't know before hand what the coordinates are going to be. On one graph my y axis might go from -50 to -10. On another it might go from 0 to 180. Is there any way to query where the origin is? Or is there another way to place the legend? Thanks, Doug Bourne Graduate Student University of British Columbia
Doug Bourne wrote:> I'm trying to automate making a bunch of figures and I need a way to > automate legend position. As I understand it the legend is placed based > on coordinates. I don't know before hand what the coordinates are going > to be. On one graph my y axis might go from -50 to -10. On another it > might go from 0 to 180. >Easiest way is to: 1) make your plot. 2) change to co-ordinate system. 3) add the legend. plot(...some stuff...) par(usr=c(0,1,0,1)) # say you want you legend at 60% across, 80% up. legend(x=0.6,y=0.8,...legend stuff...) ?par has this. Check out "usr" Cheers Jason -- Indigo Industrial Controls Ltd. http://www.indigoindustrial.co.nz 64-21-343-545 jasont at indigoindustrial.co.nz
On Sat, 04 Oct 2003 18:38:40 -0700 Doug Bourne <bournephysio at shaw.ca> wrote:> I'm trying to automate making a bunch of figures and I need a way to > automate legend position. As I understand it the legend is placed based > on coordinates. I don't know before hand what the coordinates are going > to be. On one graph my y axis might go from -50 to -10. On another it > might go from 0 to 180. > > Is there any way to query where the origin is? Or is there another way > to place the legend? > > Thanks, > Doug Bourne > Graduate Student > University of British Columbia >If you want to go a bit farther, the labcurve function in the Hmisc package can put a legend on the most empty portion of the plot automatically, or it can label curves directly, where they are most separated. --- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University
Thanks for the help everyone. par(usr) works really well for now. I'm putting the legend above the plot. I will check out the other methods if I have the time. I am really impressed with this program and community. Almost every question I have can be found with a quick search of the r-project site. The question I emailed was answered quickly and by several people. Thanks again, Doug