Skip to content

plot_layout(axes = "collect") does not work in certain situations with a facet_wrap() #367

@michaeltopper1

Description

@michaeltopper1

Hello,

It looks like the plot_layout(axes = "collect") does not work when one of the plots has a facet_wrap that has multiple rows.

Take the following example:

## In this example, the axes merge fails
library(tidyverse)

p6 <- mtcars %>% ggplot() + geom_point(aes(mpg, disp, color=cyl)) +
  labs(y = "Axes to Merge",
       x = "")

## setting the facet wrap to multiple rows
p7 <- ggplot(mtcars) + geom_point(aes(mpg, hp, color=cyl)) +
  facet_wrap(~cyl, ncol = 2) +
  labs(y = "Axes to Merge",
       x = "") 

p6 + p7 + plot_layout(guides='collect',
                      axes = "collect")

On the other hand, not having multiple rows in the p7 plot renders no issue.

## In this example, the axes merge is correct
library(tidyverse)

p6 <- mtcars %>% ggplot() + geom_point(aes(mpg, disp, color=cyl)) +
  labs(y = "Axes to Merge",
       x = "")

## not setting the facet_wrap to have multiple rows
p7 <- ggplot(mtcars) + geom_point(aes(mpg, hp, color=cyl)) +
  facet_wrap(~cyl) +
  labs(y = "Axes to Merge",
       x = "") 

p6 + p7 + plot_layout(guides='collect',
                      axes = "collect")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions