Site icon R-bloggers

Math expressions in R plots

[This article was first published on R – Statistical Odds & Ends, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Did you know that you can include math expressions in your text annotations of figures in R? This webpage has an excellent tutorial on how to do so. In essence, you can put your plot label (with some syntax) in the function expression(). Here’s a little example of that:

par(mar = c(5, 5, 4, 2))
x <- seq(0, 5, length.out = 500)
plot(x, sin(x^2), type = "l", ylab = expression(sin(x^2)),
    main = expression(paste("Plot of ", sin(x^2), " vs. x")))

To leave a comment for the author, please follow the link and comment on their blog: R – Statistical Odds & Ends.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.