Hi,
Rmardown is not capable of getting the caption title from ggplot object's title or caption (it can do that for kable's table caption for example). So if I want a figure listed in the list of figures(lof) on the top of document, the only way to achieve it is by putting the caption inside chunk header's fig.cap
. But I still prefer the ggplot original title to figure caption. + I am missing an option to put a subtitle to the plot if I go the fig.cap
way.
The best way for me would be to retain the ggplot title and to have the figure caption displayed only in the lof on top of document. It there a way to do that? Out of desperation, I tried to change the fig.cap
color to white but it made it invisible in both the lof and the figure itself.
Thanks!
Edit: Example added
---
title: "Getting rid of the caption: The story"
subtitle: "today"
author: "me"
output:
bookdown::pdf_document2:
extra_dependencies:
- float
toc: true
lot: true
lof: true
toc_depth: 2
df_print: kable
header-includes:
\usepackage{float}
\let\origfigure\figure
\let\endorigfigure\endfigure
\renewenvironment{figure}[1][2] {
\expandafter\origfigure\expandafter[H]
} {
\endorigfigure
}
include-before:
- \stepcounter{page}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=FALSE, error=FALSE, warning=FALSE, warning=FALSE, message=FALSE)
library(ggplot2)
library(dplyr)
data(iris)
iris %>%
ggplot(aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point() +
ggtitle("My preferred title", subtitle = "My preferred subtitle") +
labs(caption = "This caption does not work with the lof")