Hi all, Another plotting question I am afraid. Is there anyway of putting a legend for a plot in a margin rather than within the figure. I am trying to plot a 3x2 plot and I want to have: 1) One key along the bottom for all the plots 2) A label (a,b,c) for each plot (see previous emails) Is there any websites etc. that explain this sort of thing? Dan -- ************************************************************** Daniel Brewer, Ph.D. Institute of Cancer Research Email: daniel.brewer at icr.ac.uk ************************************************************** The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP. This e-mail message is confidential and for use by the addre...{{dropped}}
Thanks. That got me onto the right track. Because it is a multiplot and I wanted it along the bottom, I found that I had to use par(xpd=NA) and then position it relative to the last of the multiplots. After a bit of trial and error I got there. Thanks Lauri Nikkinen wrote:> Very simple example: > > opar <- par(mar = c(10, 4, 4, 4)) > plot(1:10) > lines(1:10) > par(xpd=TRUE) > legend(4,-1.5,lty=1, col="black", legend="straigh line") > par(opar) > > -Lauri-- ************************************************************** Daniel Brewer, Ph.D. Institute of Cancer Research Email: daniel.brewer at icr.ac.uk ************************************************************** The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP. This e-mail message is confidential and for use by the addre...{{dropped}}
Daniel Brewer wrote:> Hi all, > Another plotting question I am afraid. Is there anyway of putting a > legend for a plot in a margin rather than within the figure. I am > trying to plot a 3x2 plot and I want to have: > 1) One key along the bottom for all the plots > 2) A label (a,b,c) for each plot (see previous emails) > > Is there any websites etc. that explain this sort of thing?Please read the posting guide. After that, type: RSiteSearch("legend margin") Currently, the fourth entry shows a solution: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/67979.html Uwe Ligges> Dan >
Another couple of things to think about: You could use the layout function to set up your multiple plots and include an extra plotting area at the bottom to place the legend in. If you stick with the solution below then the cnvrt.coords function from the TeachingDemos package may be useful (will help you find the coordinates relative to the last plot). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Daniel Brewer > Sent: Friday, August 10, 2007 4:55 AM > To: Lauri Nikkinen; r-help at stat.math.ethz.ch > Subject: Re: [R] Plot legend in margin > > Thanks. That got me onto the right track. Because it is a > multiplot and I wanted it along the bottom, I found that I > had to use par(xpd=NA) and then position it relative to the > last of the multiplots. After a bit of trial and error I got there. > > Thanks > > Lauri Nikkinen wrote: > > Very simple example: > > > > opar <- par(mar = c(10, 4, 4, 4)) > > plot(1:10) > > lines(1:10) > > par(xpd=TRUE) > > legend(4,-1.5,lty=1, col="black", legend="straigh line") > > par(opar) > > > > -Lauri > > -- > ************************************************************** > Daniel Brewer, Ph.D. > Institute of Cancer Research > Email: daniel.brewer at icr.ac.uk > ************************************************************** > > The Institute of Cancer Research: Royal Cancer Hospital, a > charitable Company Limited by Guarantee, Registered in > England under Company No. 534147 with its Registered Office > at 123 Old Brompton Road, London SW7 3RP. > > This e-mail message is confidential and for use by the\ > ...{{dropped}}