[R] Legend for 2 plots on same screen

Daisy Englert Duursma daisy.duursma at gmail.com
Mon Aug 1 01:20:12 CEST 2011


You could make three plots. The first two you plot in and the third
one you place the legend in.


nf<-layout(matrix(c(1,2,3), 1, 3, byrow = TRUE), c(6,6,3), c(6))
layout.show(nf)

plot(sin, -pi, 2*pi, col = "blue2")
plot(sin, -pi, 2*pi, col = "darkorange3")

plot(1, xlim=c(1,2), ylim=c(1,2), type="n",axes=F, ann=F)
	legend("topleft", c("A","B"), lty=c(1,3),col= c("blue2","darkorange3"))





On Mon, Aug 1, 2011 at 4:52 AM, Cheryl Johnson
<johnson.cheryl625 at gmail.com> wrote:
> Hello,
>
> I have two plots on the same screen. I use the command par(mfrow=c(1,2)) in
> order to do this. When I try to make a legend for both plots, it only puts
> the legend in the plot on the right side. If I would like a legend that is
> outside of both of the plots, how would I do this?
>
> Thanks
>
>        [[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.
>



-- 
Daisy Englert Duursma
Department of Biological Sciences
Room E8C156
Macquarie University, North Ryde, NSW 2109
Australia

Tel +61 2 9850 9256



More information about the R-help mailing list