Skip to content

Side-by-side ggplots with working cross-reference and title #684

Answered by dragonstyle
RohanAlexander asked this question in Q&A
Discussion options

You must be logged in to vote

One approach would be to use sub figures. This would allow you to provide captions for the overall figure as well as the individual plots. In addition, your cross reference can then refer to the whole figure or either subfigure. For example:

---
title: A Simple Plot Example
format: html
---

```{r}
#| label: fig-testing
#| fig-cap: "A pair of plots, laid out side by side."
#| fig-subcap: ["Cars","Air Quality"]
#| layout: "[1, 1]"
library(ggplot2)
plt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + 
  geom_point(size = 3) + 
  theme_classic()

plt
plt2 <- ggplot(airquality, aes(Wind, Temp)) + 
  geom_point() + 
  theme_classic()

plt2
```

The overall figure @fig-testing


The firs…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@RohanAlexander
Comment options

@dragonstyle
Comment options

Answer selected by RohanAlexander
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants