[R] quick legend() question
Marc Schwartz
marc_schwartz at comcast.net
Thu Mar 22 17:21:08 CET 2007
On Thu, 2007-03-22 at 15:47 +0000, Robin Hankin wrote:
> Hi
>
> I have a scatterplot of points with pch=1 and a single point with
> pch=3, lwd=3.
> It has a high line width to attract attention to it.
>
> The following script
>
>
>
> plot(rnorm(10),rnorm(10),col="black")
> points(rnorm(10),rnorm(10),col="red")
> points(0,0,pch=3,lwd=3)
>
>
> if(TRUE){
> legend("bottomleft",c("a","b","Truth"),pch=c(1,1,3),col=c
> ("black","red","black"))
> } else {
> legend("bottomleft",c("a","b","Truth"),pch=c(1,1,3),col=c
> ("black","red","black"),lwd=c(0,0,3))
> }
>
>
> doesn't quite work as desired: the third symbol in the legend is not
> the right line width.
>
> Replacing TRUE with FALSE doesn't work as desired either; the first two
> symbols end up with a line I don't want.
> The same happens with lwd=c(NA,NA,3).
>
> How to coerce legend() into doing what I want?
Robin,
Is this what you want?
plot(rnorm(10), rnorm(10), col = "black")
points(rnorm(10), rnorm(10), col = "red")
points(0, 0, pch = 3, lwd = 3)
legend("bottomleft", c("a", "b", "Truthiness"), pch = c(1, 1, 3),
col = c("black", "red", "black"), lwd = c(0, 0, 3),
lty = c(0, 0, 1))
Add 'lty' to the legend() call so that the line types for the first two
symbols are set to 'blank'.
HTH,
Marc Schwartz
More information about the R-help
mailing list