[R] legend outside plot area
Hi, please can you help me. When I add a legend to a boxplot it appears inside the plot area, how do you get it into the margins? I have already changed the parameters so there is space for it on the margin on the right hand side of the graph. Thanks, Emily [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend outside plot area
Emily, You need to set the xpd parameter to TRUE (using par) and use a negative value for the inset argument in the legend command. For example to place a legend on the right, legend(right,inset=c(-0.3,0),legend=somelegendvector) See ?legend and play around with the values of inset to get an idea of how it works. On Sun, Aug 15, 2010 at 12:51 PM, Emily Forbes emily_for...@hotmail.co.ukwrote: Hi, please can you help me. When I add a legend to a boxplot it appears inside the plot area, how do you get it into the margins? I have already changed the parameters so there is space for it on the margin on the right hand side of the graph. Thanks, Emily [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend outside plot area
Emily Maybe this will help # Data y1=rnorm(10) y2=runif(10) x=1:10 # Set XPD and Outer Margin par(xpd=NA,oma=c(3,0,0,0)) # Plot and Legend plot(x,y1,type=n,ylab=) lines(x,y1, col=red) lines(x,y2, col=blue) legend(par(usr)[1],par(usr)[3],c(Y1,Y2),col=c(red,blue),lty=1,xjust=0, yjust=2.0) Kind regards Pete -- View this message in context: http://r.789695.n4.nabble.com/legend-outside-plot-area-tp2325864p2325938.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.