Reputation: 9628
I woult like to insert a legent to my plot. I tried this with the following code:
plot(1:4)
legend("topleft",legend=expression(paste(theta[1]==7%*%10^-4,sep=" ",theta[2]==-14%*%10^-4),
paste(theta[1]==0,sep=" ",theta[2]==0)),bty="n",cex=1.2)
Unfortunately, as you can see, the symbols of the legend are not not aligned in the vertical sence. So theta_2 in the second line appears under the value of theta_1 of the first line.
How can I change the code, so that the symbols are well aligned?
Upvotes: 1
Views: 509
Reputation: 77116
phantom()
can help, it replaces its argument by white space of specific width,
plot(1:4)
legend("topleft",legend=expression(theta[1]==7%*%10^-4~~theta[2]==-14%*%10^-4,
theta[1]==0*phantom(""%*%10^-4)~~theta[2]==0),
bty="n",cex=1.2)
Upvotes: 1
Reputation: 59990
There is an ncol
argument....
plot(1:4)
legend("topleft",legend= expression( paste(theta[1]==7%*%10^-4) ,
paste(theta[1]==0) ,
paste( theta[2]==-14%*%10^-4),
paste( theta[2]==0 ) ),
bty="n",cex=1.2 , ncol = 2 )
Upvotes: 1