[R] print tables to figure in R
Marc Schwartz
marc_schwartz at comcast.net
Tue Jul 17 14:36:57 CEST 2007
On Tue, 2007-07-17 at 09:23 +0100, ted.harding at nessie.mcc.ac.uk wrote:
> 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.
Another option is to look at the textplot() function in the 'gplots'
package on CRAN.
Also, run demo(plotmath) to look at some examples of a table/cell
layout. Specifically, the draw.title.cell() and draw.plotmath.cell()
functions used in the example output.
HTH,
Marc Schwartz
More information about the R-help
mailing list