1

When knitting my R Markdown document (papaja::apa6_pdf), my figure caption appears in the figure legend. This is the code to generate my figure:

{r RT_pilot, echo=FALSE, fig.cap="\\label{fig:RT_pilot}Median search time."}

ggplot(data=median_search_times, 
       aes(x=set_size, y=median_RT, group=response)) +
  geom_line(aes(linetype = response))

My YAML is

title             : "my title"
shorttitle        : "short title"

author: 
  - name          : "me"
    # affiliation   : "1"
    # corresponding : yes    # Define only one corresponding author
    # address       : "Postal address"
    # email         : "my@email.com"

  - name          : "my supervisor"

authornote: |


abstract: 
  <!--  -->

keywords          : "keywords"
wordcount         : "X"

bibliography      : ["r-references.bib"]

floatsintext      : yes
figurelist        : no
tablelist         : no
footnotelist      : no
linenumbers       : yes
mask              : no
draft             : no

documentclass     : "apa6"
classoption       : "man"
output            : papaja::apa6_pdf

In the output file, my figure legend is:

"Figure 2. (#fig:RT_pilot)Median search time by distractor set size for the two search tasks and two responses. Correct responses only. Error bars represent the standard error of the median."

How can I make the figure label disappear?

TanZor
  • 227
  • 1
  • 6
  • Your `label` code looks like LaTeX. If you're rendering an HTML document, I could see that causing a problem. What does your YAML header in your markdown document look like? What format do you want to use for you output document? – Limey Jun 19 '20 at 07:24
  • Hi @Limey, I'm outputing a PDF document. I've now included the YAML in my question. – TanZor Jun 19 '20 at 07:27

2 Answers2

2

Just wrapping up what has been written elsewhere:

  1. The above code works if _ (underscores) in the code-chunk name are replaced with - (minus signs). This is because papaja extends the bookdown package that requires code-chunk names not to contain underscores.
  2. While the above code works, the preferred solution is to refrain from manually setting labels (via \label{}), because it is possible to reference a figure by chunk name. Here we use RT-pilot as chunk name:
```{r RT-pilot, echo=FALSE, fig.cap="Median search time."}
library(ggplot2)
    
ggplot(data = npk) + 
  aes(x = N, y = yield, group = block) +
  geom_line(aes(linetype = block))
```

The figure can then be referenced in text by writing:

Figure \@ref(fig:RT-pilot) shows some interesting stuff...
Marius Barth
  • 596
  • 2
  • 9
0

Papaja's developer pointed me to the fact that the label must not contain _ for things to work. Changing my label to fig:RT-plot resolved the problem.

TanZor
  • 227
  • 1
  • 6