How to plot 2 ggplots side by side? #590
-
Hi everyone, Does anyone know how to present two ggplots side by side using the 2 column layout and also have only 1 single code chunk displayed before it? If I simply plot two ggplots, I can get them side by side, but I then see 2 code chunks right above the plots, one for each plot. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Testing it out, I get a single code chunk above the two plots that are side by side: # Testing References
```{r}
#| label: fig-TESTING
#| fig-cap: "A test plot."
#| 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
``` |
Beta Was this translation helpful? Give feedback.
-
The code works, thanks! Just to clarify, you need a label and the label should start with |
Beta Was this translation helpful? Give feedback.
-
Saw this discussion and I think its unfortunate that you need to add crossrefs in order to get this to work. Just made a change to our layout logic that will automatically fuse the code blocks that feed the layout: 274b86c So this code will work as of v0.9.251 (building now) ```{r}
#| 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
``` |
Beta Was this translation helpful? Give feedback.
Testing it out, I get a single code chunk above the two plots that are side by side:
The code above results in this when rendered: