New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
geom_tile() not working with facet_wrap() for different ranges of y-axes. #5740
Comments
The issue here is that the inferred height of the tiles is computed once for the plot as a whole. 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)),
height = rep(c(10, 0.1), each = 11),
var = rep(c("T1", "T2"), each = 11))
ggplot(data) +
geom_tile(aes(x = x, y = y, fill = z, height = height)) +
facet_wrap(vars(var), scales = "free_y") Created on 2024-03-04 with reprex v2.1.0 |
Oh perfect thank you for the tip! |
I'm glad there is a workaround to fix the issue, but isn't the default behavior problematic? I would have expected it to work out of the box. @teunbrand I would vote for keeping this issue open, but don't feel strongly about it. Please do as you see fit. Maybe it'd be so much work to fix that it's not worth it. |
It shouldn't be too much of a fuss to correct this. We did it in #5125 for barplots. To solve this problem we'd just have to calculate |
I found a problem when combining
geom_tile()
withfacet_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:
Created on 2024-03-04 with reprex v2.1.0
The text was updated successfully, but these errors were encountered: