The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Kickstarting R - Adding text to a plot

Text labels

The text() function allows us to put text on the plot where we want it. An obvious use is to label a line or group of points.

text(c(2,2),c(37,35),labels=c("Non-case","Case"))

This would give us two labels in the upper right corner of the plot, which with appropriate arrows could be used in place of a legend. Note that vectors were supplied as the coordinates. The first label would be centered at (2,37), and the second at (2,35), as the default alignment is to center the labels.

Text labels can also be placed in the margins of a plot using the mtext() function.

> mtext(c("Low","High"),side=1,line=2,at=c(5,7))

This would place the words "Low" and "High" on the second line below the X axis centered at 5 and 7 units. Note that the documentation declares that "user coordinates" in mtext() do not match those on the plot, but it appears that they do at the moment (R-1.6.2).

For more information, see An Introduction to R: Low-level plotting commands.

Back to Table of Contents

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.