【问题标题】:Make graphics the same size (width & height) when side by side in Rmarkdown html document在 Rmarkdown html 文档中并排时使图形大小(宽度和高度)相同
【发布时间】:2021-11-01 06:20:30
【问题描述】:

我知道如何使用 Rmarkdown 在 html 输出中并排放置多个图

{r maps, fig.cap = "Fig. Z - Maps", fig.show="hold", out.width="25%", fig.align = "center", echo = FALSE}

knitr::include_graphics("plots/X1.map.png")
knitr::include_graphics("plots/X2.map.png")
knitr::include_graphics("plots/X3.map.png")
knitr::include_graphics("plots/X4.map.png")

这些地图中的每一个都是使用 tmap 函数创建和保存的,以相同的高度和宽度保存每个地图:

tmap_save(X1.map, "plots/X1.map.png", height = 4, width = 1.5)

但是,当将 html 文档编织在一起时,地图虽然具有相同的宽度,但具有不同的高度。

任何帮助将不胜感激。

【问题讨论】:

  • 如果您包含一个简单的reproducible example 以及可用于测试和验证可能的解决方案的示例输入,则更容易为您提供帮助。
  • 另外所有的图都是相同的纵横比吗?

标签: r r-markdown tmap


【解决方案1】:

您是否尝试过在全局块选项中设置图的大小?如果您没有这些绘图的代码而不是保存的 png,这可能不起作用。

knitr::opts_chunk$set(fig.width=x, fig.height=y)

或者,如果您只能访问 png,您可以试试这个:

knitr::include_graphics("plots/X1.map.png"){ width=z% }
knitr::include_graphics("plots/X2.map.png"){ width=z% }
knitr::include_graphics("plots/X3.map.png"){ width=z% }
knitr::include_graphics("plots/X4.map.png"){ width=z% }

将 x、y 和 z 替换为您想要的值。

【讨论】:

  • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
猜你喜欢
  • 1970-01-01
  • 2017-11-27
  • 2017-01-30
  • 1970-01-01
  • 2017-12-08
  • 1970-01-01
  • 2020-08-04
  • 2016-05-13
相关资源
最近更新 更多