简体   繁体   中英

create pretty PDF report file in R

I am done with all analysis and would like to output a summary report in only one pdf file. The first page, I would like to write bold and big "Report" in the middle. Second page, I would like to insert a table(I have this data frame in R) with a very short table title. The rest pages are my graphs. One page, one graph.

Currently,my pdf file only have four pages. Any idea that I can the first page and second page. Thank you!

pdf()
plot1  #page 1
plot2  #page 2
plot3  #page 3
plot4  #page 4
dev.off()

Here's a Sweave version of what you want:

\documentclass[a4paper, titlepage]{article}
\title{Report}
\author{}
\date{}

\begin{document}
\SweaveOpts{concordance=TRUE}

\makeatletter
\vspace*{\fill}
{\centering\Huge\bfseries\@title\par}
\vspace*{\fill}
\makeatother

\newpage

\subsection*{Table}
<<results=tex, echo=FALSE>>=
library(xtable)
print(xtable(data.frame(x = rnorm(20), y = rnorm(20))), floating = FALSE)
@

\newpage

\subsection*{Plot 1}

<<plot1, fig=TRUE, echo=FALSE>>=
plot(rnorm(100))
@
\newpage

\subsection*{Plot 2}

<<plot2, fig=TRUE, echo=FALSE>>=
plot(rnorm(100))
@
\newpage

\subsection*{Plot 3}

<<plot3, fig=TRUE, echo=FALSE>>=
plot(rnorm(100))
@
\newpage

\subsection*{Plot 4}

<<plot4, fig=TRUE, echo=FALSE>>=
plot(rnorm(100))
@

\end{document}

You should save it as "MyReport.Rnw" and then can compile it using

Sweave("MyReport.Rnw")
tools::texi2pdf("MyReport.tex")

RStudio has a great interface for compiling PDFs from .Rnw files. You can also knitr with LaTeX formatted files (as opposed to RMarkdown). You'll need to run the above file through knitr::Sweave2knitr("MyReport.Rnw") first. You can even use a LaTeX editor Lyx with knitr (see http://yihui.name/knitr/demo/lyx/ ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM