[R] legend with mixed boxes and lines (not both)

From: Michael Toews <mwtoews_at_sfu.ca>
Date: Mon, 14 May 2007 18:13:21 -0700


Hi,
I seem to be unable to get a mixed legend that has lines *or* polygons (not both). For example:

ppi <- seq(0,2*pi,length.out=21)[-21]
frame()
plot.window(ylim=c(-5,5),xlim=c(-5,5),asp=1) polygon(cos(ppi)*4+rnorm(20,sd=.2),sin(ppi)*4+rnorm(20,sd=.2),

    col="green",border=FALSE)
polygon(cos(ppi)*2+rnorm(20,sd=.1),sin(ppi)*2+rnorm(20,sd=.1),

    col="blue",border=FALSE)
abline(0,2,col="red")
legend("topleft",legend=c("out","in","line"),bty="n",

    fill=c("green","blue",NA),col=c(NA,NA,"red"),     lwd=c(NA,NA,1))

I'm really guessing the behaviour in the legend() call, by setting fill to NA for the item, etc. I also tried fill=c("green","blue",FALSE), but that didn't go over too well either. I also tried adding "merge=TRUE", but that just puts the line into the box. I also tried using box.lwd=c(1,1,0), but that also did not work Is there either a way to do this or a clean workaround? Thanks in advance. +mt



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 and provide commented, minimal, self-contained, reproducible code. Received on Tue 15 May 2007 - 01:19:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 15 May 2007 - 04:31:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.