Thursday, September 01, 2011

Add text aligned to legend in R plot

What I meant is to add text on a R plot when there is already legend on it. Like the left plot in above figure, another piece of text was put exactly below the legend "Pearson'r ...RMSE = 1.9". Here is the code for that: 

l=legend("topleft", paste("Pearson's r =", R, "(p-value:", pvalue , ")\nRMSE =", RMSE), bty="n", cex=2)  
text(x=l$text$x, y=l$text$y-l$rect$h/2, "text you want to put", adj=c(0,1))

No comments:

Post a Comment