Skip to content

node overflow error when using facets and patchwork #6606

@jhollway

Description

@jhollway

I found a problem with using ggplot2 v4.0.0 together with patchwork. The code below results in the following error:

Error in `<current-expression>` : node stack overflow
Error during wrapup: node stack overflow
Error: no more error handlers available (recursive errors?); invoking 'abort' restart

With ggplot2 < 4.0.0, this would produce a plot that combined the line plot and a density plot to the right hand side of it.

Here is the code to reproduce the bug:

library(ggplot2)
library(patchwork)

df <- data.frame(
  sim = rep(1:10, 2),
  value = rnorm(20),
  name = rep(c("A", "B"), each = 10)
)

facet_spec <- facet_grid(name ~ ., scales = "free", switch = "y")

p1 <- ggplot(df, aes(sim, value)) +
  geom_line() +
  facet_spec

p2 <- ggplot(df, aes(y = value)) +
  geom_density() +
  facet_spec

wrap_plots(p1, p2, ncol = 2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions