Bioconductor / BiocStyle

Issues and pull requests for BiocStyle should go here.
12 stars 20 forks source link

How to reference multiple plots from the same code chunk #43

Open lcolladotor opened 6 years ago

lcolladotor commented 6 years ago

Hi,

In previous versions I was able to use \@ref(fig:chunkname1) and \@ref(fig:chunkname2) if a single Rmd chunk (here called chunkname) generated two plots. In the current devel version (2.7.8) this doesn't work.

You can see an example at http://research.libd.org/recount-brain/example_SRP027383/example_SRP027383.html that matches this commit https://github.com/LieberInstitute/recount-brain/commit/614316ab53b37025545078dfbbb04e9a979678b4. I include a screenshot here for simplicity.

screen shot 2018-02-27 at 9 28 04 pm

I also tried using \@ref(fig:chunkname-1) and it failed. Note that \@ref(fig:chunkname) did work, but it doesn't make sense to me to reference several figures with the same number (even if they come from the same code chunk) as in:

screen shot 2018-02-27 at 9 29 55 pm.

I guess that I could use \@ref(fig:chunkname)-1 and \@ref(fig:chunkname)-2 although the links won't point to the correct location.

Is is still possible to reference multiple plots from the same chunk? Maybe there's a new syntax that I'm missing. There are cases where I can't break the code and separate the code so that each code chunk makes a single figure. For example, when a function makes more than 1 plot.

Thanks! Leo

aoles commented 6 years ago

Hi Leo, thanks for reporting this. Actually, the problems you are experiencing might indicate an issue with bookdown responsible for managing references, as the following doesn't produce links either.

---
title: "Cross-referencing multiple figures"
output:
  bookdown::html_document2
---

References to Figure \@ref(fig:plot1) and Figure \@ref(fig:plot2).

```{r plot, fig.cap=c("First", "Second"), fig.pos="h"}
plot(cars)
plot(faithful)
```

For some reason the former approach described in https://github.com/rstudio/bookdown/issues/343 doesn't work anymore. Do you happen to know which was the last bookdown version which was fine?

lcolladotor commented 6 years ago

Hi Andrzej,

Thanks for looking into this! From http://bioconductor.org/help/workflows/recountWorkflow/ I believe that it still worked with bookdown version 0.5. My current version is 0.7. It's not the most narrow clue but hopefully it helps.

Best, Leo