Hi there, I plot a simple plot with the following code: plot (rnorm(1:10), type = "b") legend("top", "test", lty = 1, pch = 21) The result is something wired for the line crosses the point in the legend while the line does not cross the point in the main plot. Is there possibility to draw the legend that line does not cross the point, i.e., like the pattern in the main plot? Any help is really appreciated. Best regards, Jinsong
Hi, May be this helps. set.seed(55) ?x<-rnorm(1:10) ?plot(x,type="n",xaxt="n",yaxt="n") ?legend1<- legend("top","test",lty=1,pch=21) range1<- range(x) ?range1[2]<- 1.05* (range1[2]+ legend1$rect$h) ?plot(x,ylim=range1,type="b") ?legend1<- legend("top","test",lty=1,pch=21) A.K. ----- Original Message ----- From: Jinsong Zhao <jszhao at yeah.net> To: R help <r-help at r-project.org> Cc: Sent: Sunday, September 22, 2013 11:54 PM Subject: [R] legend for the plot with type = "b" Hi there, I plot a simple plot with the following code: plot (rnorm(1:10), type = "b") legend("top", "test", lty = 1, pch = 21) The result is something wired for the line crosses the point in the legend while the line does not cross the point in the main plot. Is there possibility to draw the legend that line does not cross the point, i.e., like the pattern in the main plot? Any help is really appreciated. Best regards, Jinsong ______________________________________________ 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 Sep 22, 2013, at 10:54 PM, Jinsong Zhao wrote:> Hi there, > > I plot a simple plot with the following code: > > plot (rnorm(1:10), type = "b") > legend("top", "test", lty = 1, pch = 21)?par plot (rnorm(1:10), type = "b") legend("top", "test", lty = "69", pch = 21)> > The result is something wired for the line crosses the point in the > legend while the line does not cross the point in the main plot. > > Is there possibility to draw the legend that line does not cross the > point, i.e., like the pattern in the main plot? > > Any help is really appreciated.-- David Winsemius, MD Alameda, CA, USA
On 09/23/2013 01:54 PM, Jinsong Zhao wrote:> Hi there, > > I plot a simple plot with the following code: > > plot (rnorm(1:10), type = "b") > legend("top", "test", lty = 1, pch = 21) > > The result is something wired for the line crosses the point in the > legend while the line does not cross the point in the main plot. > > Is there possibility to draw the legend that line does not cross the > point, i.e., like the pattern in the main plot? > > Any help is really appreciated. >Hi Jinsong, A bit messy, but doable: plot (rnorm(1:10), type = "b") library(plotrix) legendg(x=sum(par("usr")[1:2])/2,y=par("usr")[4], legend="test",pch=list(c(45,1,45)),col=list(c(1,1,1))) I plan to add the "top" etc. positions to the legendg function in the near future. Jim