Include figure labels in R markdown for side by side plots

前端 未结 1 367
无人共我
无人共我 2021-01-29 03:52

In my rmarkdown document, I want to include plots side by side to save space. For example, I want to include:

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

相关标签:
1条回答
  • 2021-01-29 04:20

    Adapting my answer from this post, you can combine cross-referencing by including the output format bookdown::pdf_document2". Note that I am manually appending the subfigure letter to the cross reference i.e. \@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)
    ```
    

    0 讨论(0)
提交回复
热议问题