2

我发现了这个关于在 Sweave 中更改 ggplot2 图的大小的问题。我添加了Sweaveopts{width=3, height=3}它,它确实缩小了绘图的大小,但它并没有缩小文本。所以最后,轴上的所有数字都重叠了。

有没有办法在 Sweave 中缩放整个 ggplot2 图,这样我就不必手动缩放原始 ggplot2 调用中的每个组件?这似乎是我应该能够做的事情,但我在 ggplot2 书或网站上找不到它。谢谢!

FWIW,这是我在 Sweave 中的电话:

\SweaveOpts{width=3, height=3}
\begin{figure}
\begin{center}
<<fig=TRUE>>=
print(plot.m)
@
\end{center}
\caption{stuff}
\label{fig:stuff}
\end{figure}

以及生成 ggplot2 图的调用:

plot.m <- ggplot(temp, aes(date, spread)) + geom_bar(stat="identity") + scale_x_date(major="years", minor="months")
4

1 回答 1

6

它基本上是一个 Sweave 常见问题解答。谷歌,你会发现大量的点击。

一种方法是将文件写入 pdf(无缩放),然后根据\includegraphics命令进行缩放。我刚刚看了几天前完成的一个小插图,我想要的东西大约和页面一样宽,我做到了:

\begin{figure}[t!]
  \centering
<<someLabel,fig=TRUE,width=8>>=
## some R code omitted
print(dotplot(foo ~ bar | someFactor, group=someThing, 
              data=someDF, layout=c(1,3),
              xlab="some X label", ylab="",
              key=simpleKey(text=c("A","B"), space="top")))
@
  \caption{Some caption.}
  \label{fig:someLabel}
\end{figure}

在 Sweave 选项级别,有些基本上只有一个宽度尺寸。我发现小值效果不好——所以尝试更大的值,例如 6 或 7 英寸。

于 2010-12-21T02:48:03.990 回答