Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

errors in figure caption in r markdown caption outside float

I tried to put the plot objects in r markdown. The fig.cap worked well in the first r chunk. However problems occurred when I tried to put the second figure. Please see the code below.

The YAML looks like this

output:
  bookdown::pdf_document2:
    toc: no
header-includes:
- \usepackage{setspace}\doublespacing
- \usepackage{float}
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{amsmath}
- \usepackage{multicol}
- \usepackage{threeparttable}
- \usepackage{caption}

The code in r chunk is

{r trend_1, echo=F, fig.cap='The air pollution trend of different groups',out.width='50%',message=F, fig.show='hold'}

The code for plotting is (these are two plot objects)

state.con.oz
state.con.pm

I got an error ! Package caption Error: \caption outside float. Any ideas?

BTW, I wonder how to create a figure footnote in r markdown?

Thanks in advance.

like image 754
Yabin Da Avatar asked Dec 07 '22 10:12

Yabin Da


1 Answers

Try to name your R code chunk without underlines

```{r trend1, echo=F, fig.cap='The air pollution trend of different groups',out.width='50%',message=F, fig.show='hold'}

your_plot
```
like image 145
J_F Avatar answered Jan 19 '23 02:01

J_F