Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lcolladotor opened this issue Feb 28, 2018 · 2 comments
Open

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

lcolladotor opened this issue Feb 28, 2018 · 2 comments

Comments

@lcolladotor
Copy link

lcolladotor commented Feb 28, 2018

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 LieberInstitute/recount-brain@614316a. 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

lcolladotor added a commit to LieberInstitute/recount-brain that referenced this issue Mar 3, 2018
@aoles
Copy link
Collaborator

aoles commented Mar 27, 2018

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 rstudio/bookdown#343 doesn't work anymore. Do you happen to know which was the last bookdown version which was fine?

@lcolladotor
Copy link
Author

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

@lshep lshep self-assigned this Apr 16, 2018
@lshep lshep removed their assignment Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants