有没有一种方法可以像生成一个图(即用pdf()或ggsave())一样从R生成一个表的PDF?我知道有其他程序(使用sweave等)的方法,但我想从R生成它。创建一个PDF表格
32
A
回答
30
是的,因为您可以将文本放入图形中,因此放入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))
4
还有在plotrix包addtable2plot功能。
14
另请参阅grid.table
的gridExtra
,使用网格图形。
4
我最近想这样做,但不喜欢grideExtra
或textplot
的输出格式,所以我写了这个函数来做胶乳。这是一个黑客位工作,并有与sweave
或knitr
更好的方法,但你可能会发现它很有用修改你的目的:
createPDF <- function(xx, name=deparse(substitute(xx))){
require(xtable)
tt <- print(xtable(xx), type='latex')
texfile <- paste0('./reports/', name, '.tex')
cat(
'\\documentclass[12pt]{report}
\\usepackage[landscape]{geometry}
\\date{}
\\begin{document}', tt, '\\end{document}', sep='',
file=texfile
)
## pdflatex from texlive package for linux converts .tex to .pdf
system(paste0('pdflatex ', '-output-directory ./reports ', texfile))
}
相关问题
- 1. Drupal - 创建一个表格
- 2. 从Python中创建一个不含pdflatex的latex pdf表格
- 3. 在Objective C中创建一个PDF表格
- 4. 如何从ASP.Net web创建PDF表格
- 5. 水晶报表 - 从一个报表创建多个PDF
- 6. 如何创建一个pdf合并几个单独的pdf格式在r
- 7. 加入多个表格并创建一个表格
- 8. 创建一个这样的HTML表格
- 9. 创建一个可点击的表格
- 10. 在gridview中创建一个表格
- 11. 创建一个php联系表格
- 12. 创建一个PHP注册表格
- 13. 从视图创建一个表格?
- 14. SQL从多个表格创建表格
- 15. 使用按钮来创建一个PDF格式截图数据的HTML表单
- 16. 创建一个简单的PDF模式
- 17. Wicket:创建一个PDF文件链接
- 18. 创建一个简单的pdf
- 19. 为iPhone创建一个PDF,如何?
- 20. 如何创建一个polyglot PDF?
- 21. PDF小丑:创建列表
- 22. 从现有表格迭代以创建另一个表格 - Qlikview
- 23. 如何使用另一个表格的列创建表格?
- 24. 如何用两个表格中的唯一行创建表格
- 25. 如何从另一个旧表格创建新表格
- 26. Xcode iPhone - 在视图内创建一个表格(不是表格)
- 27. 我想创建一个嵌套的表格或表格行
- 28. JavaFX - IText - 创建PDF时创建PDF
- 29. 创建一个网格,没有空格使用表格html
- 30. 使用iTextSharp签署一个PDF表格
谢谢,这似乎是工作! – Tom 2010-10-07 13:34:03