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 Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743
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
Try pt.lwd= instead of lwd= in your legend call. On 3/22/07, Robin Hankin <r.hankin at noc.soton.ac.uk> 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 Hankin > Uncertainty Analyst > National Oceanography Centre, Southampton > European Way, Southampton SO14 3ZH, UK > tel 023-8059-7743 > > ______________________________________________ > 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. >