开发者

Adding a table of contents to PDF with R plots

开发者 https://www.devze.com 2023-04-12 23:21 出处:网络
I\'m creating a larger number of plots in R and save them as PDF (using grDevices / pdf). Is there an easy way to add a (meta-data) table of contents to the PDF as it is created?

I'm creating a larger number of plots in R and save them as PDF (using grDevices / pdf). Is there an easy way to add a (meta-data) table of contents to the PDF as it is created?

I don't mean to add a separate page, but a TOC that PDF viewers like Preview.app display in the sidebar to make navigation easier.)

Example of such a TOC开发者_开发问答:

Adding a table of contents to PDF with R plots


The only way I know is with LaTeX, but you don't necessarily need Sweave; perhaps you could just generate the LaTeX file directly with your RPython code. If you've got two pictures which are 6x6 (the default size) named tmp-001.pdf and tmp-002.pdf, this is how you'd make a section called Section A with two subsections for the two pictures.

\documentclass{article}
\usepackage[paperwidth=6in, paperheight=6in, margin=0in]{geometry}
\usepackage{hyperref}
\usepackage{graphicx}
\parindent 0pt
\begin{document}
\pdfbookmark[1]{Section A}{anchorname_aa}

\pdfbookmark[2]{plot aa}{anchorname_aa}
\includegraphics{tmp-001.pdf}

\newpage
\pdfbookmark[2]{plot bb}{anchorname_bb}
\includegraphics{tmp-002.pdf}

\end{document}


You could create a first page using the names of your objects or plots as the arguments to text in columns.

plot(1:10,1:10, type="n", main ="Index", axes=FALSE,frame.plot=FALSE,xlab="")

text(1,10, "plot")
text(3,10, "page")
text(5,1:10, rev(1:10+1))
text(2,1:10, rev(letters[1:10]))

Adding a table of contents to PDF with R plots

I cannot think of a way to generate a navigable TOC, but this option may be more pleasing and easier to integrate with Beamer-type displays. The Hmisc package function latex provides an interface to the Latex longtable package. My Latex-fu is weak but if yours is stronger, you could also divert the dvi code that is created for integration within other applications. I get an intermediate dvi file put in a temporary directory which then opens my dvi viewer and allows saving as pdf:

require(Hmisc)
?latex  # you will probably want to review this
latex(Plot_list<-data.frame(Plots=letters[1:10], Pages=2:11))

Adding a table of contents to PDF with R plots


Not as far as I know. I think you have to use sweave for that.

0

精彩评论

暂无评论...
验证码 换一张
取 消