【发布时间】:2020-06-09 13:38:00
【问题描述】:
我在使用 Rmarkdown 的多个图表中使用子标题时遇到问题。我希望我的所有 4 个图形都对齐并居中,但是当我设置 fig.ncol = 1 时,只有最后一个图形居中,其他 3 个图形稍微偏右。
我已经尝试解决的问题:
- 将 fig.ncol = 1 替换为 fig.sep = c('\newline', '\newline', '\newline'),但结果相同
这是我的代码:
---
title: "Test"
author: "My Name"
output: pdf_document
header-includes:
- \usepackage{subfig}
---
```{r, echo = FALSE, fig.cap = "Main Title", fig.subcap=c("Sub1","Sub2", "Sub3", "Sub4"), out.width='.30\\linewidth', out.width='.30\\linewidth', fig.asp=1, fig.ncol = 1, fig.align = c('center')}
library(ggplot2)
# line chart
p1<- ggplot(pressure, aes(x = temperature, y = pressure)) +
geom_line()
# step chart
p2<-ggplot(pressure, aes(x = temperature, y = pressure)) +
geom_step()
# line chart with points
p3<-ggplot(pressure, aes(x = temperature, y = pressure)) +
geom_line() +
geom_point()
# line chart
p4<-ggplot(pressure, aes(x = temperature, y = pressure)) +
geom_line()
p1
p2
p3
p4
```
输出如下所示:
任何想法如何让我的 4 个图表居中?提前致谢。
【问题讨论】:
标签: r r-markdown markdown knitr tex