-
Notifications
You must be signed in to change notification settings - Fork 2.1k
allow coord_fixed()
with facet_grid(..., scales = "free", space = "free")
when x and y scales are discrete
#4584
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
Comments
I would like to second this (or at least something similar), for an additional use-example while using geom_tile() in order to constrain the rectangular shapes. The ability to combine coord/aspect specifications and free scaling was especially convenient for multi-panel, faceted tile plots, and even further if different aesthetics are desired. Can there somehow be exceptions for discrete axes perhaps?
Please let me know if anything in this request was unclear. |
I'm generally fine with this if it can be implemented in a clean way |
Copying @baderstine's comment from #3834 (comment), which describes why the combination of ok, this should help:
Plot 1: has the correct aspect ratio, but it includes every single x category in every facet, regardless of whether a value is actually present:
Plot 2: drops the irrelevant x categories in each facet, however my tiles are not the shape that i want (square):
Plot 3: drops irrelevant x categories and each facet's size is constant but the facets with more x categories are now squished... more categories, more squish. :(
Plot 4: drops irrelevant x categories and allows the size of each x facet to vary based on how many categories are in it, and with a specific aspect ratio applied, i can now make nice little squarish boxes. |
not me, @baderstine I believe |
Aw, yes... Sorry for the noise. |
It makes sense that it’s not possible to mix
facet_grid(..., scales = "free", space = "free")
withcoord_fixed()
in most situations. However, I think that it should be possible and makes sense to allow this when both, x and y, scales are discrete.For example, a use case in this reprex with
ggplot2
version 3.3.4:Here, we have different numbers and levels of factors in x scale, so it’s necessary to use
scales = "free"
andspace = "free"
for efficient use of space.When I make plots like this one, I like to make sure that the breaks on x and y axes are placed equidistantly (so the background grid is made of squares), which would generally be accomplished with
coord_fixed()
but not possible in this case since we are using free scales and space.As of version 3.3.3 of
ggplot2
it was possible to still accomplish this withoutcoord_fixed()
by the (perhaps hacky and off-label) use oftheme(aspect.ratio = 1)
, also pointed out in this SO post. See reprex below with version 3.3.3. This is however no longer possible since this bug was fixed (#4432).It would be great if this can be accomplished legitimately with
coord_fixed()
rather than by using hacks. Based on my admittedly superficial understanding, I think that the use ofcoord_fixed()
when faceting with free scales and space should be legitimate as long as the x and y scales are discrete.Created on 2021-08-12 by the reprex package (v2.0.0)
The text was updated successfully, but these errors were encountered: