如何使用 r/sweave/latex 在页面上的 ggplot 中平铺绘图

问题描述 投票:0回答:1

我正在使用 R/Sweave/Latex 创建一篇包含 ggplot 图的文章。我想在一页上平铺 4 个图,我想知道最好的方法是什么?我的其中一张图的代码如下,但即使只有一张图,我在调整它的大小和对齐它时也遇到问题

谢谢

\begin{figure}
\centering{}
<<echo=FALSE,fig=TRUE, width = 10>>=
DisPlot
@
  \vspace*{-35mm}
  \caption{Test caption}
\label{fig:Test}
\end{figure}
r ggplot2 sweave
1个回答
0
投票

使用 par() 将绘图平铺在网格中。使用 \setkeys{Gin} 更改页面内的大小。这是一个工作示例

<<echo = FALSE>>==
x <- c(1,2,3)
y <- c(4,5,6)
@

\documentclass{article}
\usepackage{tcolorbox}
\begin{document}
\SweaveOpts{concordance=TRUE}

\setkeys{Gin}{width=1.0\textwidth,keepaspectratio}
\begin{figure}
<<fig = TRUE, echo = FALSE >>==
par(mfrow = c(2,2))
plot(x,y)
plot(x,y)
plot(x,y)
plot(x,y)
@
\end{figure}

\end{document}
© www.soinside.com 2019 - 2024. All rights reserved.