Figures captions and labels in knitr

前端 未结 1 715
野性不改
野性不改 2020-12-23 09:37

I\'m new to Knitr. I\'m trying to make a report using r chunks, and I can\'t figure out how to use captions and labels to reference the figure later on. Here\'s an example

相关标签:
1条回答
  • 2020-12-23 10:17

    You can achieve this by including fig_caption: yes in the header:

    ---
    title: "Plotting"
    output:
      pdf_document:
        fig_caption: yes
    ---
    
    ```{r figs, echo=FALSE, fig.width=7,fig.height=6,fig.cap="\\label{fig:figs}plotting example"}
    par(mfrow=c(2,2))
    plot(1:10, col=2)
    plot(density(runif(100, 0.0, 1.0)))
    plot(runif(100, 0.0, 1.0),type="l")
    ```
    
    in Figure \ref{fig:figs} we see examples of plotting in R.
    

    Note that the figure caption label should be included in the caption with a double backslash, as shown above.

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