Signature and inscription numbers in a book

I am new to Knitra. I am trying to report using r chunks, and I cannot figure out how to use captions and labels to refer to the picture later. Here is an example of what I would like to do:

--- title: "Plotting" author: "xx" date: '2015-08-10' output: pdf_document --- ```{r figs, echo=FALSE, fig.width=7,fig.height=6,fig.cap="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. 

I would like to have the heading "Example of construction" and have a shortcut, so in the text I can use Figure \ ref {fig.label}. I tried fig.cap and fig.lp, none of them work. I would appreciate it if someone could help.

+5
source share
1 answer

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. 

Click here to view a screenshot.

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

+14
source

All Articles