Skip to content
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

strange problem under a fixed aspect coordinates #175

Closed
ghost opened this issue May 10, 2020 · 1 comment
Closed

strange problem under a fixed aspect coordinates #175

ghost opened this issue May 10, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented May 10, 2020

Thanks for developing such a nice package.

There's a very strange problem under a fixed aspect coordinates, and here's a simple example to reproduce the problem.

df1 <- data.frame(x = 1:10, y = rnorm(10))
df2 <- expand.grid(x = 1:10, y = 1:10)
df2$value <- rnorm(100)
df3 <- data.frame(x = runif(10, 0, 3), y = 1:10)

library(ggplot2)
library(patchwork)
p1 <- ggplot(df1, aes(x, y)) +
  geom_point() +
  scale_x_continuous(limits = c(0.5, 10.5), expand = c(0, 0)) +
  coord_fixed()

p2 <- ggplot(df2, aes(x, y, fill = value)) +
  geom_tile() +
  scale_x_continuous(limits = c(0.5, 10.5), expand = c(0, 0)) +
  scale_y_continuous(limits = c(0.5, 10.5), expand = c(0, 0)) +
  coord_fixed()

p3 <- ggplot(df3, aes(x, y)) +
  geom_col() +
  scale_x_reverse() +
  scale_y_continuous(limits = c(0.5, 10.5), expand = c(0, 0)) +
  coord_fixed()
plot_spacer() + p1 + p3 + p2 +
  plot_layout(nrow = 2, byrow = TRUE, guides = "collect")

unnamed-chunk-1-1

p1 + plot_spacer() + p2 + p3 +
  plot_layout(nrow = 2, byrow = TRUE, guides = "collect")

unnamed-chunk-1-2

p3 + p2 + plot_spacer() + p1 +
  plot_layout(nrow = 2, byrow = TRUE, guides = "collect")

unnamed-chunk-1-3

p2 + p3 + p1 + plot_spacer() +
  plot_layout(nrow = 2, byrow = TRUE, guides = "collect")

unnamed-chunk-1-4

@thomasp85
Copy link
Owner

There is unfortunately quite a lot of heuristics going on to figure out space optimisation with multiple fixed aspect plots, so the order of the plots does have an influence. I don't think I can come up with a reasonable solution since there are quite a number of ill-defined issues when multiple fixed aspect plots share rows and columns simultaneously.

All that being said I think I've fixed this particular inconsistency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant