如何解决如何在R降价bookdown中添加子图
我正尝试在R bookdown项目中添加带有子标题的图形,如下所示
---
output:
pdf_document:
extra_dependencies: "subfig"
---
```{r echo=F,out.width = "50%",fig.showtext=TRUE,fig.show='hold',fig.cap="TITULO"}
par(mfrow=c(1,2))
knitr::include_graphics("ts_mult.png")
knitr::include_graphics("ts_ad.png")
```
我得到以下结果
然后我尝试如下添加子标题(“ imagen a”,“ imagen b”)
```{r echo=F,fig.cap="TITULO",fig.subcap=c("imagen a","imagen b")}
par(mfrow=c(1,2))
knitr::include_graphics("ts_mult.png")
knitr::include_graphics("ts_ad.png")
```
但这没用,它会引发以下错误
! Undefined control sequence.
<recently read> \subfloat
Error: LaTeX failed to compile Tesis_AE.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.
如何正确添加子标题?
解决方法
您只需要在块中添加fig.subcap=c("A subtitle","Another subtitle")
。
在我的环境中,至少fig.showtext=TRUE
不是必需的,而是会导致错误:Error in loadNamespace(name) : there is no package called 'showtext' Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart Execution halted
。这就是为什么我在答案中排除了设置。
---
output:
pdf_document:
extra_dependencies: "subfig"
keep_tex: yes
---
```{r echo=F,out.width = "50%",fig.show='hold',fig.cap="TITULO",fig.subcap=c("Subtitulo1","Subtitulo2")}
par(mfrow=c(1,2))
knitr::include_graphics("your-path-to/image1.png")
knitr::include_graphics("your-path-to/image2.png")
```
会话信息
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=Japanese_Japan.932 LC_CTYPE=Japanese_Japan.932 LC_MONETARY=Japanese_Japan.932
[4] LC_NUMERIC=C LC_TIME=Japanese_Japan.932
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2
> rmarkdown::pandoc_version()
[1] ‘2.7.3’
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。