更改 Sweave 中 ggplot2 图的大小,而不使文本/数字过大
我发现这个关于更改的问题 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")
I found this question about changing the size of a ggplot2 plot in Sweave. I added the Sweaveopts{width=3, height=3}
and it does shrink the size of the plot, but it doesn't scale down the text. So in the end, all of the numbers on the axes overlap.
Is there a way to scale the entire ggplot2 plot in Sweave so that I don't have to manually scale every component in the original ggplot2 call? It seems like something I should be able to do, but I can't find it in the ggplot2 book or on the website. Thanks!
FWIW, here's my call in Sweave:
\SweaveOpts{width=3, height=3}
\begin{figure}
\begin{center}
<<fig=TRUE>>=
print(plot.m)
@
\end{center}
\caption{stuff}
\label{fig:stuff}
\end{figure}
And the call that generates the ggplot2 plot:
plot.m <- ggplot(temp, aes(date, spread)) + geom_bar(stat="identity") + scale_x_date(major="years", minor="months")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这基本上是一个 Sweave 常见问题解答。谷歌一下,你会发现无数的点击。
一种方法是将文件写入 pdf(不缩放),然后使用
\includegraphics
命令进行缩放。我刚刚看了几天前完成的一个小插图,我想要一些大约与页面一样宽的东西,我做到了:有些基本上只是 Sweave 选项级别的一个宽度尺寸。我发现较小的值效果不佳 - 因此请尝试较大的值,例如 6 或 7 英寸。
It's basically a Sweave FAQ. Google and you will find a gazillion hits.
One approach is to just write the file to pdf (no scaling) and to then scale on the
\includegraphics
command. I just looked at a vignette I finished a couple of days ago where I wanted something approximately as wide as the page and I did:some basically just one width dimension at the Sweave options level. I found that small values do not work well -- so try something bigger as eg 6 or 7 inches.