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

facet_grid(space = "free") can work with coord_fixed() #5977

Merged
merged 4 commits into from
Aug 26, 2024

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #4584.

Briefly, we set the ratio of a panel when space = "free" and using coord_fixed().

Previously, in #4432 it was prohibited to set an aspect ratio in the theme and using free space.
However, there is a subtlety here. The theme aspect ratio controls the width/height of panels directly and you cannot reasonably set this ratio for multiple panels of disparate sizes. So theme aspect ratios still aren't allowed. The coord aspect ratio controls the data proportion that is consistent with free facet space, so this should be allowed.

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

df <- data.frame(
  x = c("length a", "length b", "area", "mass", "density", "height"),
  y = c("a", "b", "c", "c", "b", "a"),
  f = c("A", LETTERS[1:5])
)

ggplot(df, aes(x, y)) +
  geom_tile() +
  facet_grid(~f, scales = "free", space = "free") +
  coord_fixed(1)

Created on 2024-07-05 with reprex v2.1.0

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit 3a7ae74 into tidyverse:main Aug 26, 2024
13 checks passed
@teunbrand teunbrand deleted the facet_coord_fixed branch August 26, 2024 12:44
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

Successfully merging this pull request may close these issues.

allow coord_fixed() with facet_grid(..., scales = "free", space = "free") when x and y scales are discrete
2 participants