[R] plotting only text as a table
Marc Schwartz
mschwartz at medanalytics.com
Wed Jul 10 17:43:49 CEST 2002
> -----Original Message-----
> From: Stephan Holl [mailto:sholl at gmx.net]
> Sent: Wednesday, July 10, 2002 9:44 AM
> To: MSchwartz at medanalytics.com
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] plotting only text as a table
>
> Dear Marc
>
> > 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.
> as a newbi it is not easy to understand that code, but I try hard.
> perhaps you can provide some code-snippets for viewing...
>
> thanks anyway
>
> cheers
> steph
Let me give you an example using my second option. This will generate a
text table with a centered title and two columns below. One column with
left aligned text and one column with right aligned numbers.
# This preserves current graphic parameters
# for restoration at the end
old.par <- par(no.readonly = TRUE)
# This sets the plot region margins to be thin
par(mar = c(1, 1, 1, 1) + 0.1)
# this sets up the empty plot window
# with x-axis range as 0 to 4 and
# the y-axis range as 0 to 6
# with no labels and no plot frame
plot(0, 0, xlim = c(0, 4), ylim = c(0, 6),
type = "n", axes = FALSE, ann = FALSE,
frame.plot = FALSE)
# Set a vector of text for the left aligned column
Col1 <- c("This is Row 1", "This is Row 2...", "This is Row 3.....")
# Set a vector of numbers for the right aligned column
# First set up some real numbers, then format them with
# only one decimal place each using formatC()
Col2 <- c(4, 5.3785, 6.345)
Num <- formatC(Col2, digits = 1, format = "f")
# Now plot the text on the graphic window
# First plot text for a centered title, with large text (cex = 2.0)
text(2, 5, labels = "This is a centered title", cex = 2.0)
# Finally, plot the number column as right aligned.
# Note the use of pos = 4
# Use y-axis values of 4, 3, 2
# with a x-axis value of 1
text(1, c(4, 3, 2), labels = Col1, pos = 4, cex = 1.0)
# Finally, plot the number column as right aligned.
# Note the use of pos = 2
# Use y-axis values of 4, 3, 2
# with a x-axis value of 3
text(3, c(4, 3, 2), labels = Num, pos = 2, cex = 1.0)
# Restore Graphic Parameters
par(old.par)
If you need other examples or formatting help, let me know. Keep in
mind that in my example, the y-axis runs from bottom to the top with
increasing numbers (0 to 6). Note that the text() function y-axis
coordinate values decline as the actual row number text values (Row 1,
Row 2, Row 3) that I used increase.
Regards,
Marc
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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