I am knitting an Rmarkdown document to HTML with bookdown::html_document2
. How can I include both a title above the figure and a note below the figure?
For example, this code lets me produce a figure with a title above the figure. But how can I also include a note below the figure?
To be clear, I do not want to include the note below the ggplot with + labs(caption = "Text")
, I want to have the note separate from the plot in the same HTML style as the figure title above the figure (as is common in scientific publications).
---
title: "Reprex"
output:
bookdown::html_document2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(fig.topcaption = TRUE) # Display figure title above the figure
```
Figure \@ref(fig:figure) shows some results.
```{r figure, fig.cap="Figure Title (which I want above the figure)"}
library(tidyverse)
mtcars %>%
ggplot() +
aes(x = wt, y = mpg) +
geom_point()
```
1 Like
cderv
July 29, 2021, 1:03pm
2
I fear that this is not yet possible.
opened 09:11PM - 24 Jun 21 UTC
next
feature
In my field it seems customary to separate the title/short description of a figu… re from its notes (containing lengthy details), similar to
![figure notes](https://i.stack.imgur.com/7xtCW.png)
Is there any way to accomplish this with Rmarkdown/knitr or would it make sense to add a chunk option specifically for this purpose? Stack Overflow offers [one solution](https://stackoverflow.com/questions/61344827/how-to-create-a-figure-note-below-the-figure-caption-in-r-markdown-and-bookdown) for latex documents that works and surprisingly does not even result in ugly latex code.
However, the markup in the Rmarkdown file is verbose and other output formats won't accept the code. Many packages for producing tables have an option to provide both a title and notes, for example
```r
modelsummary::modelsummary(mods, title = "...", notes = "...")
```
But I am not aware of a package that allows producing figures with captions that are not baked into the actual image file. So in my opinion, a chunk option for this purpose would be a welcome addition although I do not know how and whether this could be implemented and whether you like the idea at all. For latex specifically, I was thinking that perhaps the existing chunk option `fig.scap` could be used because I assume in most cases the short title of a figure would also be used in the list of figures (抛砖引玉而已). But I do not know of a way to have Latex print this short caption outside of the list of figures.
---
By filing an issue to this repo, I promise that
- [x] I have fully read the issue guide at https://yihui.org/issue/.
- [x] I have provided the necessary information about my issue.
- If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
- If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included `xfun::session_info('knitr')`. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: `remotes::install_github('yihui/knitr')`.
- If I have posted the same issue elsewhere, I have also mentioned it in this issue.
- [x] I have learned the Github Markdown syntax, and formatted my issue correctly.
I understand that my issue may be closed if I don't fulfill my promises.
Is this what you would like ?
Hi @cderv , thanks for the information, this is exactly what I would like. Fingers crossed that it will be implemented soon!
system
Closed
August 19, 2021, 1:26pm
4
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.