在Sweave中更改ggplot2绘图的大小,而不会使文本/数字不成比例地大

时间:2010-12-21 01:10:05

标签: r ggplot2 sweave

我发现这个question关于改变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")

1 个答案:

答案 0 :(得分:6)

这基本上是一个Sweave FAQ。谷歌和你会发现一个巨大的点击率。

一种方法是将文件写入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英寸。