过去,我使用RStudio创建ggplot2图形,然后从RSudio中导出它们为PDF文件。这非常好用。
现在我正在尝试使用knitr进行自动化处理,但我无法确定在哪里设置图形的高度和宽度,以创建高质量的输出。
这是我的当前尝试,但“并排”图形不是,并且旋转的横向图形分辨率似乎很低。
我会感激任何建议。似乎ggplot2和knitr都在积极开发中,这很棒,但是互联网搜索让我很困惑。LaTeX对我来说是新的。我也会欣赏针对这些工具集的一般工作流策略。提前致谢。
\documentclass[letterpaper]{article}
\usepackage{lscape}
\begin{document}
<<load, echo=FALSE, results='hide', warning=FALSE, message=FALSE>>=
require(ggplot2)
@
Two on the first page.
<<first, echo=FALSE, fig.height=3, fig.cap="This is first", fig.pos='h'>>=
ggplot(mtcars, aes(mpg, wt))+geom_point()+facet_grid(vs ~ am, margins=TRUE)
@
Blah, blah, blah.
<<second, echo=FALSE, fig.height=3, fig.cap="This is second", fig.pos='h'>>=
ggplot(mtcars, aes(mpg, wt))+geom_point()+facet_grid(vs ~ am, margins=TRUE)
@
\newpage
Second page.
Side by side images:
<<third, echo = FALSE, out.width="2in", fig.cap='Side by side'>>=
ggplot(mtcars, aes(mpg, wt))+geom_point()+facet_grid(vs ~ am, margins=TRUE)
ggplot(mtcars, aes(mpg, wt))+geom_point()+facet_grid(vs ~ am, margins=TRUE)
@
\newpage
\begin{landscape}
This page is rotated
<<fourth, echo = FALSE, out.width="4in", fig.cap='Landscape'>>=
ggplot(mtcars, aes(mpg, wt))+geom_point()+facet_grid(vs ~ am, margins=TRUE)
@
\end{landscape}
\end{document}