Patchwork doesn't render in Quarto

89 Views Asked by At

I would like to use patchwork to plot two graphs side by side. Unfortunately, it returns an error and I don't know why. Here is some reproducible code:

---
title: "Test"
format: html
---

```{r}
library(ggplot2)
library(patchwork)

p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))

p1 + p2
```

Output error:

Quitting from lines 7-14 [unnamed-chunk-1] 
Error in `Ops.data.frame()`:
! '==' only defined for equally-sized data frames
Backtrace:
  1. global .main()
  2. execute(...)
  3. rmarkdown::render(...)
  4. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  5. knitr:::process_file(text, output)
     ...
 30. patchwork:::build_patchwork(plot, plot$layout$guides %||% "auto")
 31. base::lapply(x$plots, plot_table, guides = guides)
 33. patchwork:::plot_table.ggplot(X[[i]], ...)
 34. patchwork:::add_guides(gt, guides == "collect")
 36. base::Ops.data.frame(guide_loc, panel_loc)

When running the code from the code chunk it does work, but when rendering the script it doesn't work. So I was wondering if anyone knows why this happens?

0

There are 0 best solutions below