过去,我使用RStudio创建ggplot2,然后将它们从RSudio中导出为PDF。这非常有效。使用knitr和RStudio将ggplot2输出嵌入到LaTeX 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}