Skip to content

coord_fixed produces strange error #156

@drmowinckels

Description

@drmowinckels

This is mainly an issue for a better error message when combining plots made with coord_fixed and facets.

The error message is quite cryptic and it tok me a while to figure out that this comes from combinations of coord_fixed and facet_wrap. I'm not sure how feasible it is to catch this and provide a better warning with solution suggestion, but thought it worth making you aware of.

library(ggplot2)
library(patchwork)

# base plots. All below are fine
p1 <- ggplot(mtcars, aes(mpg, disp)) +
  geom_point()

p1 + p1

p2 <- p1 + coord_fixed()

p1 + p2

p3 <- p1 + facet_wrap(~cyl)

p1 + p3

p2 + p3

# These make errors and look weird.

p4 <- p3 + coord_fixed()

p4 + p4
#> Warning in xList[i] <- valueList: number of items to replace is not a multiple
#> of replacement length

#> Warning in xList[i] <- valueList: number of items to replace is not a multiple
#> of replacement length

p1 + p4
#> Warning in xList[i] <- valueList: number of items to replace is not a multiple
#> of replacement length

p2 + p4
#> Warning in xList[i] <- valueList: number of items to replace is not a multiple
#> of replacement length

# fixed with plot_layout(width = 1)
p4 + p4 + plot_layout(width = 1)

Created on 2020-03-03 by the reprex package (v0.3.0)

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