4

I'm using bookdown to make a simple (one document) Rmarkdown document, knitting to HTML. I understand how to make figures with captions and reference those figures, but I would like to change the numbering on my figures. A simple example of what I'm doing is below.

---
title: "My Title"
author: "Me"
date:  "1/1/2016"
output: bookdown::html_document2
bibliography: refs.bib
---


```{r heatmap, fig.cap = "Plot showing blah blah"}
plot(mydata) 
```

The above code creates a figure labeled "Figure 1: Plot showing blah blah". I want the figure to be labeled "Figure S1: Plot showing blah blah" (note the "S" before the figure number). (I'm writing a supplement for a journal submission.) I have read into how bookdown works and it seems like I can easily accomplish this by changing one line in the _bookdown.yml file (see: https://bookdown.org/yihui/bookdown/internationalization.html). The problem is that I don't have a _bookdown.yml file, I don't know how to make one or how to link it to my .Rmd file. All I have is a .Rmd file that knits perfectly fine with working figure labels, etc.

Any help making, editing, and linking a _bookdown.yml file would be appreciated. Alternatively, are there any other ways to change the figure numbering? I don't mind the fix being annoying, I just want it to work!

Emma Talis
  • 43
  • 3

1 Answers1

3

Welcome to stackoverflow!

_bookdown.yml is a YAML file for optional settings for a bookdown project. See Yihui's documentation for an overview of available options.

You can easily generate such a file yourself, e.g., by saving an R script in RStudio with the .yml extension. There is no need for linking to link to the .Rmd file – it suffices to place it in the project directory.

The most basic _bookdown.yml that accomplishes what you need is

_bookdown.yml

language:
  label:
    fig: 'Figure S'
Martin C. Arnold
  • 9,483
  • 1
  • 14
  • 22
  • Thanks so much for your response! I tried this (I now have a _bookdown.yml file in my project directory) and unfortunately, nothing has changed in when I knit my .Rmd file. My figure labels are still "Figure 1:". Do I need to change anything in my YAML header in order for this to work? Or knit my .Rmd file in a different way than usual? – Emma Talis Sep 14 '20 at 15:50
  • 1
    That is strange. It should work if you hit the *knit* button. Maybe you didn't indent the code in *_bookdown.yml* as shown in my answer? It's important that there is a tab (two blanks) before `label:` and two tabs (four blanks) before `fig:`. – Martin C. Arnold Sep 14 '20 at 19:19
  • 1
    Yep, this fixed it. I only had one tab before the `fig:`. Thanks so much! – Emma Talis Sep 15 '20 at 16:05