[R] One pdf file with plots and text output

Dirk Eddelbuettel edd at debian.org
Wed Oct 17 15:23:28 CEST 2007


On 17 October 2007 at 10:44, Rainer M Krug wrote:
| I create one pdf file with plots via pdf() and one text file with text 
| via sink() that works very nice. But I would prefer to have one pdf file 
| with plots and the text which I store in the te=xt file via sink(). I.e.
| 
| x.lm<-lm(...)
| pdf()
| plot(x.lm)
| NOW THE TEXT OF summary(xlm) IN THE PDF FILE
| dev.off()
| 
| Is this possible or is there a different format which I could use?

Yes -- using textplot() from the gplots package. Cut & paste from its
example:

     ### Make a nice 4 way display with two plots and two text summaries

     data(iris)
     par(mfrow=c(2,2))
     plot( Sepal.Length ~ Species, data=iris, border="blue", col="cyan",
           main="Boxplot of Sepal Length by Species" )
     plotmeans( Sepal.Length ~ Species, data=iris, barwidth=2, connect=FALSE,
                main="Means and 95% Confidence Intervals\nof Sepal Length by Species")

     info <- sapply( split(iris$Sepal.Length, iris$Species),
                     function(x) round(c(Mean=mean(x), SD=sd(x), N=gdata::nobs(x)),2) )

     textplot( info, valign="top"  )
     title("Sepal Length by Species")

     reg <- lm( Sepal.Length ~ Species, data=iris )
     textplot( capture.output(summary(reg)), valign="top")
     title("Regression of Sepal Length by Species")

     par(mfrow=c(1,1))

So textplot(capture.output(summary(xlm)) may become be your new best friend.

Hth, Dirk

-- 
Three out of two people have difficulties with fractions.



More information about the R-help mailing list