Dear R users, I'm making multiple plots within the same pdf page (par(mfcol = c(5,1)), and want a legend for this at the bottom of all the plots. From previous mails it has been suggested to use par(xpd=TRUE), increase the margin at the last plot, and then draw the legend. However, when I do this, the last plot gets smaller with the same amount I increase the margin with. The problem seems to be that legend() is drawing inside of the margins of the last plot. While what I want is to get this legend outside the margins. Or, extend the margins, without making the plot itself shrink... Any hints or tips will be greatly appreciated. Best regards, Lars ------ Here is my suggestion, which does not work too well: pdf("rmsd_open_closed.pdf", height=9) opar <- par(mfcol = c(4,1), mar=c(4,4,2,1) ) plot() plot() plot() par(mar=c(7,4,2,1)) plot() par(xpd=TRUE) legend(0, 8, c("black line", "red line"), col=c(1,2), lty=c(1,1)) par(opar) dev.off() [[alternative HTML version deleted]]
Use outer margins around the whole thing, see argument "oma" in ?par. Uwe Ligges On 20.01.2010 17:53, Lars Skj?rven wrote:> Dear R users, > I'm making multiple plots within the same pdf page (par(mfcol = c(5,1)), and > want a legend for this at the bottom of all the plots. From previous mails > it has been suggested to use par(xpd=TRUE), increase the margin at the last > plot, and then draw the legend. However, when I do this, the last plot gets > smaller with the same amount I increase the margin with. > > The problem seems to be that legend() is drawing inside of the margins of > the last plot. While what I want is to get this legend outside the margins. > Or, extend the margins, without making the plot itself shrink... > > Any hints or tips will be greatly appreciated. > > Best regards, > Lars > > ------ > Here is my suggestion, which does not work too well: > > pdf("rmsd_open_closed.pdf", height=9) > opar<- par(mfcol = c(4,1), mar=c(4,4,2,1) ) > > plot() > plot() > plot() > > par(mar=c(7,4,2,1)) > plot() > > par(xpd=TRUE) > legend(0, 8, c("black line", "red line"), col=c(1,2), lty=c(1,1)) > > par(opar) > dev.off() > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
On 01/21/2010 03:53 AM, Lars Skj?rven wrote:> Dear R users, > I'm making multiple plots within the same pdf page (par(mfcol = c(5,1)), and > want a legend for this at the bottom of all the plots. From previous mails > it has been suggested to use par(xpd=TRUE), increase the margin at the last > plot, and then draw the legend. However, when I do this, the last plot gets > smaller with the same amount I increase the margin with. > > The problem seems to be that legend() is drawing inside of the margins of > the last plot. While what I want is to get this legend outside the margins. > Or, extend the margins, without making the plot itself shrink... >Hi Lars, I would try using layout for something like this: x11(width=5,height=10) layout(matrix(1:6,ncol=1),heights=c(rep(1,5),0.5)) plot(1:10) plot(1:10) plot(1:10) plot(1:10) plot(1:10) oldmar<-par(mar=c(1,1,1,1)) plot.new() legend(0.45,1,c("one","two","three"),pch=1:3) par(oldmar) Jim