更改 Sweave 中 ggplot2 图的大小,而不使文本/数字过大

发布于 2024-10-08 20:30:30 字数 746 浏览 0 评论 0原文

我发现这个关于更改的问题 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟酉 2024-10-15 20:30:30

这基本上是一个 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 英寸。

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:

\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}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文