【问题标题】:Include figure labels in R markdown for side by side plots在 R markdown 中包含图形标签以进行并排图
【发布时间】:2019-03-10 03:21:37
【问题描述】:

在我的 rmarkdown 文档中,我想并排包含绘图以节省空间。例如,我想包括:

plot(rnorm(100))
hist(runif(100))

plot(rnorm(100))
hist(runif(100))

我真的不在乎两个子图都有一个标题,还是每个子图都有一个标题。我只是真的想并排包含数字,并有一些方法可以引用它们(图 1 等)。有人有建议吗?我的标题中有这个:

标题包括: - \usepackage{subfig}

当我的块中没有“fig.show='hold'”时,我的所有字幕都可以正常工作,但我的情节不会并排显示。当我添加 fig.show='hold' 时,布局看起来很棒,但标题消失了。

【问题讨论】:

  • 如何以par(mfrow=c(1,2)) 开头使两个图出现在同一个图中?您可能需要修改宽度,以免它们被挤到一个图形的空间中。

标签: r latex r-markdown subfigure


【解决方案1】:

根据this post 调整我的答案,您可以通过包含输出格式bookdown::pdf_document2"来组合交叉引用。请注意,我手动将子图字母附加到交叉引用,即\@ref(fig:fig-sub)a

---
output: bookdown::pdf_document2
header-includes:
   - \usepackage{subfig}
---  

See Figures \@ref(fig:fig-sub)a and \@ref(fig:fig-sub)b

```{r fig-sub, echo = FALSE, fig.cap='two plots', fig.subcap=c('one plot', 'the other one'), out.width='.49\\linewidth', fig.asp=1, fig.ncol = 2}
plot(1:10)
plot(rnorm(10), pch=19)
```

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-31
    • 2015-04-24
    • 2020-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多