Skip to content

geom_tile() not working with facet_wrap() for different ranges of y-axes. #5740

Closed
@FloLecorvaisier

Description

@FloLecorvaisier

I found a problem when combining geom_tile() with facet_wrap() when the y-axes of the different facets have fairly different ranges.

I expected that both facets exhibit the same kind of plot, but the one with the greatest range on the y-axis looks odd. Note that creating separate plots (i.e., without using facets but using a subset of the data) make the tiles work for both plots.

Here is the code to reproduce the bug:

library(ggplot2)

data <- data.frame(x = rep(seq(0, 1, length.out = 11), each = (11) * 2),
                   y = c(seq(100, 200, length.out = 11), seq(0, 1, length.out = 11)),
                   z = rnorm(((11) ** 2 * 2)),
                   var = rep(c("T1", "T2"), each = 11))

ggplot(data) +
  geom_tile(aes(x = x, y = y, fill = z)) +
  facet_wrap(vars(var), scales = "free_y")

Created on 2024-03-04 with reprex v2.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions