figure captions, references using knitr and markdown to html

前端 未结 5 800
迷失自我
迷失自我 2020-12-05 04:00

I\'m writing an Rmd file, to be processed by knitr into HTML. It contains some R chunks that generate figures, which get stored as data URIs in HTML.

1) How do I add

5条回答
  •  生来不讨喜
    2020-12-05 04:53

    Also very late to the party I changed Yihuis suggestion here that he also linked above to do referencing.

    ```{r functions, include=FALSE}
    # A function for captioning and referencing images
    fig <- local({
        i <- 0
        ref <- list()
        list(
            cap=function(refName, text) {
                i <<- i + 1
                ref[[refName]] <<- i
                paste("Figure ", i, ": ", text, sep="")
            },
            ref=function(refName) {
                ref[[refName]]
            })
    })
    ```
    ```{r cars, echo=FALSE, fig.cap=fig$cap("cars", "Here you see some interesting stuff about cars and such.")}
    plot(cars)
    ```
    
    What you always wanted to know about cars is shown in figure `r fig$ref("cars")`
    

提交回复
热议问题