[R] plotting only text as a table

Marc Schwartz mschwartz at medanalytics.com
Wed Jul 10 15:24:07 CEST 2002

> -----Original Message-----
> From: owner-r-help at stat.math.ethz.ch
[mailto:owner-r-help at stat.math.ethz.ch] On
> Behalf Of Stephan Holl
> Sent: Wednesday, July 10, 2002 5:19 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] plotting only text as a table
> Dear R-Gurus,
> I am preparing a multiple-plot-sheet with 2rows and 2 columns, but
> are actually only 3 plots to plot.
> the 4. part of my sheet should contain a table with simple statistic
> values like n, mode, standard deviation....
> I cannot handle to plot the information in the plot. the summary()
> function prints it to the xtrem instead of the plot.
> Here is an example-plot with the 3 plots and the empty 4.th space.
> http://frosch.2y.net/tmp/ws_34_geol_20.png
> Perhaps there is a nice sollution.
> btw. I produce the plot in BATCH-mode.
> Thanks so far.
> steph

Two approaches:

1. Review the math formula table plots that are towards the end of the
demo(graphics) programs, which plot a row/column matrix of cells.  There
are some generic functions in that code to create the table matrix and
plot text in the cells.

2. What I recently did was to use the plot() function to create a
graphic window with enough horizontal rows (ie. Y-axis range) to contain
titles, spaces and the textual data that I wish to display.  I also set
the window margins fairly narrow [ie. par(mar = c(1, 1, 1, 1) + 0.1) ],
so that I could use most of the window for drawing text within the plot

Using the text() function, I then draw the text at the appropriate
row/column positions to create the table with column alignments as I
require.  If you define the plot vertical range appropriately, you can
use integer values of Y for the vertical row centers.  Then it is a
matter of adjusting the x-axis value to the columns you wish to create
and the "cex" parameter in text() to set the text size that looks good
for your table.

One note, if you wish to create a column of right aligned numbers, where
the decimal points are lined up, use the formatC() function to define
the number of digits after the decimal place [ie. formatC(Number, digits
= 2, format = "f") ].  Then use "pos = 2" in the text() function [ie.
text(x, y, Number, pos = 2) ], which will draw the text to the left of a
given x-axis reference point.  

Conversely, if you wish to have generic text that is left aligned, use
"pos = 4", which will plot the text to the right of a given x-axis
reference point.

This took some trial and error for me to get it to work, but it gets the
job done. 

If you want to create lines in your table (ie. cell boundaries, etc),
you can use the segments() function for this.

As you do with your 3 data plots, be sure to adjust the above so that it
works within your 2 x 2 graphic matrix.



r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list