Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
258 views
in Technique[技术] by (71.8m points)

r - Create a PDF table

Is there a way to produce a PDF of a table from R in the same way you produce a plot (ie with pdf() or ggsave())? I realize there are ways with other programs (using sweave etc.), but I would like to produce it just from R.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes there is as you can place text into graphs and hence into pdf devices.

The nicest wrapper for this may be the textplot() function in Greg Warnes' trusted gplots package. Below is the beginning of the examples section of its help page:

# show R version information
textplot(version)
# show the alphabet as a single string
textplot( paste(letters[1:26], collapse=" ") )

# show the alphabet as a matrix 
textplot( matrix(letters[1:26], ncol=2))

### 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
of 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))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...