Skip to main content

6.6) More On Graphics: Annotation


Annotation

It’s possible to incorporate all sorts of symbols and styles into text for annotating graphs. The basic function expression() can be used wherever text is specified - e.g. inside a plot() command for the xlab= or main= arguments, or in the separate functions text() or mtext() (which adds text in the margins).

Inside the brackets of expression() you can type things in programming format to be translated into mathematical notation. Greek letters are also recognized by name. So, for example: expression(sum(x[i], i==1, n)) gives a summation symbol with appropriate annotation; expression(sqrt(phi)) gives the Greek letter phi with a square root symbol around it. Also, italic() gives italic font; [] produces subscripts and ^ produces superscripts.

For more information, use ?plotmath or demo(plotmath) and ?Hershey or demo(Hershey). You can combine mathematical notation and ordinary text by simply concatenating the items using *; if you need brackets, spaces, etc., remember to put them inside quotation marks. There are also some escape characters: e.g. \n starts a new line.