4
votes

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.

1
Can you provide a MWE with YAML header etc.? BTW: have a look at bookdown for footnotes, cross-referencing etc. - J_F
@J_F I just added the YAML header. Unfortunately, I did not find any information regarding footnotes in bookdown. - Yabin Da
@J_F Add table footnote is handy with threeparttable::footnote. However, figure note is complicated. - Yabin Da
Try to name your R code chunk without underlines ... works for me. - J_F
@J_F Works for me as well. Thanks! - Yabin Da

1 Answers

16
votes

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
```