r - 创建一个PDF表格

标签 r

有没有一种方法可以像生成图一样(例如,使用pdf()或ggsave())从R中生成表格的PDF?我意识到可以使用其他程序(使用sweave等)来实现某些方法,但是我只想从R中生成它。

最佳答案

是的,因为您可以将文本放入图形中,因此也可以放入pdf设备中。

最好的包装器可能是Greg Warnes的受信任gplots软件包中的textplot()函数。以下是其帮助页面的示例部分的开头:

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

关于r - 创建一个PDF表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3881278/

相关文章:

r - 按字母顺序排序时,字母 "y"位于 "i"之后

r - 有没有办法使用R来打破图表轴并打破线性回归线?

r - 如何编写可以引用输入图的 ggplot '+' -pipeable 函数

r - 替代 R 中的 `str()`

R: `match` 中的行为与列表不一致

R Snowfall - 难以实现调用其他函数的函数

r - 何时使用map()函数以及何时使用summarise_at()/mutate_at()

r - 按分隔符拆分列并删除包含在其他值中的值

r - 使用包 "cmprsk"在 R 中自定义竞争风险图

r - 在 R 中构建多层栅格上的温度分布的任何解决方法