[R] print tables to figure in R
(Ted Harding)
ted.harding at nessie.mcc.ac.uk
Tue Jul 17 10:23:37 CEST 2007
On 16-Jul-07 22:11:31, Steve Powers wrote:
> Doe anyone know of a way to print nice-looking, printer-friendly tables
> directly in the R plot window? This would be very handy for examining
> preliminary results from frequently used routines. I've hunted for this
> with no luck. All anyone seems to do is export text files to excel for
> formatting, or use the print(bla) function which just calls the numbers
> at the command line. There must be a way to do this.---steve
It would certainly be possible to write a function include a table
within a plot, since a table is no more than bits of text laid out
positionally in an array, and there is already provision to place
text at assigned positions on a plot -- the function text() does this.
That being said, though, writing the code to layout a particular
table in the particular way you want would not be trivial. I don't
know of an R function which implements a reasonable "default layout"
for arbitrary tables in a plot.
As an example of "doing it with your bare hands", run the following:
x<-0.5*(0:20);y<-(x^2)/10;plot(x,y,pch="+",col="blue",ylim=c(-10,10))
lines(x,y,col="blue")
A<-c(0,2.5,5,7.5,10); B<-(A^2)/10;points(A,B,pch=2,col="red")
Ach<-as.character(round(A,digits=1))
Bch<-as.character(round(B,digits=3))
text(x=c(6.25,8.0),y=c(0,0),labels=c("A","B"),pos=4)
for(i in (1:5)){text(x=6.125,y=(-1-i),labels=Ach[i],pos=4)}
for(i in (1:5)){text(x=7.875,y=(-1-i),labels=Bch[i],pos=4)}
You could augment this with grid lines, etc. according to taste.
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 17-Jul-07 Time: 09:23:33
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list