我想将绘图与 knitr 生成的 pdf 文档的页面中心对齐。我可以使用 fig.align='center'
将绘图水平对齐到中心但无法弄清楚如何使绘图与中心垂直对齐。
我一直在使用以下代码:
---
header-includes: \usepackage{graphicx}
output:
pdf_document
geometry:
left=1in,right=1in,top=1in,bottom=1in
---
```{r,fig.align='center',out.extra='angle=90', echo=FALSE}
library(ggplot2)
ggplot(diamonds, aes(y=carat, x=price, colour=clarity))+geom_point()+
facet_wrap(~cut)
```
最佳答案
在 LaTeX 方面,垂直居中的图形必须是 figure
with position p
.如何使用 knitr
实现这一点要看:
figure
中环境(见 fig.env
)。然后只有附加选项 fig.pos = 'p'
需要。 figure
环境:\begin{figure}[p]
```{r,fig.align='center',out.extra='angle=90', echo=FALSE}
library(ggplot2)
ggplot(diamonds, aes(y=carat, x=price, colour=clarity))+geom_point()+
facet_wrap(~cut)
```
\end{figure}
请注意,这在编译为 PDF 时有效,但将您限制为 PDF 作为输出格式。
关于r - 使用 Knitr 将绘图居中到页面中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33922757/