Bookdown 中的图像脚注

Image footnotes in Bookdown

如何在 bookdown::pdf_document2 中的图片下方添加图形注释?对于 ggplot2 创建的图来说,这相对容易。 grid.arrange 可以用 grid.arrange(<plot>, bottom = <figure_notes>) 完成工作。但是如果我手动插入一个图像,例如knitr::include_graphics(rep("images/knit-logo.png", 3)),有没有办法给它添加一个图形注释?我看到一个 knitr 选项,fig.subcap。但这无法编译:

```{r fig.show="hold", fig.cap = "a", fig.subcap = "b"}

knitr::include_graphics(rep("images/knit-logo.png", 3))

```

这个returns:

This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6350 64-bit)
entering extended mode
! Undefined control sequence.
<recently read> \subfloat 

Error: Failed to compile miniSample.tex. See miniSample.log for more info.

谢谢

找到权宜之计:

  1. 使用magick::image_read将图像读入R;
  2. 使用 rasterGrob;
  3. 将图像转换为 raster 项目
  4. textGrob创建一个笔记;使用grid.arrange来呈现;
  5. 使用 grid.arrange.

    出示图片和笔记

    plot_A <- magick::image_read(<path>) %>% rasterGrob(interpolate = TRUE) note <- textGrob("This is a note.") grid.arrange(plot_A, bottom = note)

如果你想使用子图,你必须在 LaTeX 中加载 subfig 包。这可以通过使用 YAML 中的 header-includes 参数来完成,如 here.

所述

这是一个最小的、可重现的例子,它创建了一个本地图像 "temp.jpg",然后生成了三个子图:

---
output: pdf_document
header-includes:
   - \usepackage{subfig}
---

```{r}
jpeg(filename = "temp.jpg")
plot(cars)
dev.off()
```

```{r fig.show="hold", fig.cap = "a", fig.subcap = c("Your Caption", "Another Caption", "Isn't this great"), fig.ncol = 3, out.width="33%"}
knitr::include_graphics(rep("temp.jpg", 3))
```

Check out this post for the original description: Subfigures or Subcaptions with knitr?