如何在使用knitr的rmarkdown中并排显示两张图片?

3
在Rmarkdown中,我想要将两张来自网页的图片并排打印。我正在尝试这样做。
```{r, echo=FALSE, out.width="33%", fig.align = "center", fig.cap="Examples of the FPTP bias: In Prairies (left) and Greater Toronto area (right). Source: www.fairvote.ca"}

knitr::include_graphics(
  c("https://www.fairvote.ca/wp-content/uploads/2019/12/Western-alienation-website-FPTP-page.png", "https://www.fairvote.ca/wp-content/uploads/2019/12/Toronto-Peel-halton-2019-results-website-FPTP.jpg")
  )

```

但是我得到的是这样的——它们仍然一个在另一个上面打印:

enter image description here

请指导。注意:我不想使用 cowplot 或任何其他包。
1个回答

7

在参数中加入 fig.show='hold'

```{r, echo=FALSE, out.width="33%", fig.align = "center", fig.show='hold', fig.cap="Examples of the FPTP bias: In Prairies (left) and Greater Toronto area (right). Source: www.fairvote.ca"}
knitr::include_graphics(
  c("https://www.fairvote.ca/wp-content/uploads/2019/12/Western-alienation-website-FPTP-page.png",
    "https://www.fairvote.ca/wp-content/uploads/2019/12/Toronto-Peel-halton-2019-results-website-FPTP.jpg")
)
```

现在它看起来像这样:现在它看起来像这样。


1
谢谢!仅供参考,这个主题也在R Markdown Cookbook中有涉及:https://bookdown.org/yihui/rmarkdown-cookbook/figures-side.html - Yihui Xie
太棒了!非常感谢。有没有一种方法可以在图像之间插入字符,例如knitr :: include_graphics(“a)”,c(“https://www.fairvote.ca/wp-content/uploads/2019/12/Western-alienation-website-FPTP-page.png”,“b)” “https://www.fairvote.ca/wp-content/uploads/2019/12/Toronto-Peel-halton-2019-results-website-FPTP.jpg”))-这样我们就可以将图像称为“见图1.b”? - IVIM
@IVIM 不确定这个问题,我没有做过。也许你可以开一个新的问题! - Werner Hertzog

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接