Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to using text() to adding text to a plot

Tags:

This may be a naive question, but I was wondering if there's a better way than using text() to adding text to a plot. Note, I'm also using layout() as well. Specifically, I have a section of a plot where I would like to add some text with headings followed by regular text.

text() is fine it seems for simple annotations, but to get the spacing right for several lines of text seems to require a lot of manual manipulation of the x and y and cex parameters. Any suggestions?

like image 787
andrewj Avatar asked Oct 15 '09 04:10

andrewj


People also ask

Which function is used to add text labels to a plot?

R – text () Function text () Function in R Programming Language is used to draw text elements to plots in Base R. Parameters: x and y: numeric values specifying the coordinates of the text to plot. labels: the text to be written.

How do I add text to a graph in Matlab?

To add text to one point, specify x and y as scalars. To add text to multiple points, specify x and y as vectors with equal length. text( x , y , z , txt ) positions the text in 3-D coordinates. text(___, Name,Value ) specifies Text object properties using one or more name-value pairs.

How do I add a text box to a Matlab figure?

Create Text Box AnnotationCreate a simple line plot and add a text box annotation to the figure. Specify the text description by setting the String property. Force the box to fit tightly around the text by setting the FitBoxToText property to 'on' .


2 Answers

Here are some alternative options to consider:
- the gplots package has a textplot function to add some text output in a base graphics plot.
- plotrix has a function addtable2plot
- for grid graphics grid.text() is available and in gridExtra there is a function grid.table() (see, e.g., R-Wiki)

like image 133
rcs Avatar answered Nov 11 '22 16:11

rcs


If you're using base graphics, then text() is probably your best bet, and fiddling with coordinates etc is part of the game. If you want to learn a new framework, the lattice package is a reworking of the basic approach to plotting in R. It be installed by default so help(package='lattice') will get you started.

Here's a pretty good guide (pdf) to graphics in general in R, with a substantial section on lattice: download

like image 45
Peter M Avatar answered Nov 11 '22 16:11

Peter M