O'Reilly logo

R: Data Analysis and Visualization by Ágnes Vidovics-Dancs, Kata Váradi, Tamás Vadász, Ágnes Tuza, Balázs Árpád Szucs, Julia Molnár, Péter Medvegyev, Balázs Márkus, István Margitai, Péter Juhász, Dániel Havran, Gergely Gabler, Barbara Dömötör, Gergely Daróczi, Ádám Banai, Milán Badics, Ferenc Illés, Edina Berlinger, Bater Makhabel, Hrishi V. Mittal, Jaynal Abedin, Brett Lantz, Tony Fischetti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding text descriptions to graphs

Sometimes, we might wish to add descriptions to a graph, say if we are producing a PDF for a presentation or as a handout with notes. In this recipe, we will learn how to add text descriptions in the margins of a graph, instead of having to add them separately in another program.

Getting ready

We are only using the base graphics functions for this recipe. So, just open up the R prompt and type in the following code. You might wish to save the code as an R script for later use.

How to do it...

Let's plot a random normal distribution and add a little bit of description after the graph:

par(mar=c(12,4,3,2)) plot(rnorm(1000),main="Random Normal Distribution") desc<-expression(paste("The normal distribution has density ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required