I'm trying to produce a gallery of ggplot2
geoms using knitr
. In order to do this quickly I thought to use the built-in example
s to populate the content.
After some trial and error I've got to this point:
documentclass[a4paper,titlepage]{tufte-handout}
usepackage{pdflscape}
usepackage{graphicx}
usepackage{alltt}
<<setup, include=FALSE, cache=FALSE>>=
options(replace.assign=TRUE,tidy=TRUE)
library(ggplot2)
library(plyr)
library(scales)
geoms <- setdiff(apropos("^geom_"),"geom_blank")
@
itle{ggplot2 Gallery}
egin{document}
maketitle
<<examples, echo=FALSE, comment=NA>>=
for(i in geoms){
writeLines(paste0("\section{",gsub("_","\\_",i),"}"))
do.call("example",list(i))
}
@
end{document}
But there are still a number of issues I can't resolve:
I can't seem to be able to mix markup
and asis
results options within the chunk so that section headings get produced. (This will be crucial for navigation of the document later). Is there any other way of producing writing LaTex within the chunk?
There are some examples which throw errors (which is why geom_blank
is excluded). The knitr documentation states that computation continues in the case of errors, but it only seems to be the knit process which continues; the example loop ceases at that point. Is there a way to avoid the parts of the examples that are errors?
The example
code output isn't syntaxed highlighted. (Useful but not essential).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…