# Add text aligned to legend in R plot

September 1, 2011
By

(This article was first published on One Tip Per Day, and kindly contributed to R-bloggers)

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))