Reputation: 1040
I am adding text to a plot in R but right now the alignment of the last part of the text is off. I am trying to align the R2 part of the text under the two blahs. This is just an example.
Example
plot(1:10)
text(8,4,expression("blah \nblah\n"~R^2~"= 0.98"),col="red")
Any help would be appreciated.
Thanks
Upvotes: 0
Views: 5254
Reputation: 1610
I would use expression
only in the expression used, and use the adj
parameter to adjust alignment.
plot(1:10)
text(8,4,c("blah \nblah\n", expression(paste(R^2, "= 0.98"))),col="red", adj = 0)
Additionaly, it seem like you're trying to do some legend. You could use legend
to do it:
legend('bottomright', c('blah', 'blah', expression(paste(R^2, "= 0.98"))))
This would be more readable code, and you can adjust settings according to your needs. Check ?legend
for more information.
Upvotes: 1