[R] Legend in the outer margin

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Apr 10 15:04:02 CEST 2006


Prasanna wrote:

> Dear Rs
> 
> I have a 3x3 multiple plot. I would like to have a overall legend in
> the outer right margin.
>>From the help archive, I found that it can be done by setting
> par(xpd=NA). However, I couldn't find the correct values
> for x and y co-ordinates for the legend. Please find the code snippet below:
> 
> par(mfrow=c(3,3), mar=c(4,4,0.9,0.5), oma=c(1,2,2,4),cex.main=1.1)
> 
>   *postscript(*file=epsfile,onefile=FALSE,horizontal=TRUE*)*
> 
> /* some plotting */
> 
> par(xpd=NA)

You get the user coordinates of the plotting region by
   par("usr")
Now simply make the legend right of that plotting region, e.g. with
x corrdinates at
   par("usr")[2] + epsilon
and y coordinates at
   mean(par("usr")[3:4])

Uwe Ligges



> legend(legend=c("2h-opt Exact","1-shift Exact","2p-opt Exact"),
> lty=c("solid","dashed","dotdash"),lwd=c(2,2,2),col=c("red","green","black"),
> bty="n",cex=0.8)
> 
> Thanks in advance
> Prasanna
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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