r - Prevent lines from appearing twice in the legend -
i have asked question legend hour or ago align symbols in legend, new issue has emerged. add lines legend. ried following:
plot(1:4) legend("topleft",legend=expression(theta[1]==7%*%10^-4,theta[1]==0, theta[2]==-14%*%10^-4,theta[2]==0), lty=c(2,1),lwd=2,col=c("blue","grey"),bty="n",cex=1.2,ncol=2) 
but lines should appear once per line: 1 blue line in first line , 1 grey line in second line. tried inserting zeros, lty=c(2,1,0,0), there appears space between thetas.
it should this:

has suggestion how can prevent lines appearing twice in legend?
actually lines appearing 4 times because have created 4 element expression vector. (the lines argument being recycled.) solution "protects" interior commas interpretation, althoug looking @ again see order not indended. should able fix have demonstrated how better incorporate commas in expressions:
plot(1:4) legend("topleft",legend=expression(theta[1]==7%*%10^-4*","~theta[1]==0, theta[2]==-14%*%10^-4*","~theta[2]==0), lty=c(2,1),lwd=2,col=c("blue","grey"),bty="n",cex=1.2,ncol=2) you may need adjust location since impinges on fourth point, again not use case. consider using ncol=1.

response edit: didn't want commas spaces. add more tildes:
png(); plot(1:4) legend("topleft",legend=expression(theta[1]==7%*%10^-4~theta[2]==-14, theta[1]==0 ~~~~~~~~~~~~theta[2]==0), ncol=1, lty=c(2,1),lwd=2,col=c("blue","grey"),bty="n",cex=1.2);dev.off() 
Comments
Post a Comment