I have several data frames and graphs that I want to place into a pdf file. I know of Sweave and knitr, but they both use latex to create a pdf file, and I don't want users of the code to need to download Latex before they can use it. Is there any way at all to send data frames into as a table (with a title) and graphs as the same document? If not, is there any way to send the data frames into one document and the graphs into another? I'd be glad to see any reasonable way, as long as it's possible to make it all automated.
Asked
Active
Viewed 3,645 times
3 Answers
6
One basic example,
library(gridExtra); library(ggplot2)
ggsave("plotntable.pdf", arrangeGrob(qplot(mpg, cyl, data=mtcars),
tableGrob(mtcars[1:10, 1:4]), ncol=2))

baptiste
- 75,767
- 19
- 198
- 294
3
The plotrix package has the function addtable2plot
, so you could open a pdf device and create your plots, then for the tables just create an empty plot (plot.new
and plot.window
) and use addtable2plot
to put the data frame (if it is small enough) into the empty plot.

Greg Snow
- 48,497
- 6
- 83
- 110
2
Yes, for graphs.
pdf(file = "pdf_demo.pdf")
plot(rnorm(10), rnorm(10))
dev.off()
See ?pdf
for details, and ggsave
if you're using ggplot2
.
I'm not so sure about tables. You may be able to use pandoc
and Rmd
. Or just write the tables as .csv
. Pandoc, at least, can be installed pretty easily using the installr
package. Edit looks like Pandoc uses LaTeX to create PDF's.

Gregor Thomas
- 136,190
- 20
- 167
- 294