-
Notifications
You must be signed in to change notification settings - Fork 2k
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
AsIs sometimes not preserved when computing geom parameters #5863
Comments
Thanks June! I think the following things are happening.
The following is what I think the plot should yield. The clipping/margins are added for clarity. library(ggplot2)
data.frame(x = 1:2, y = c(0.5, 2)) |>
ggplot(aes(x, I(y))) +
geom_col(position = "identity") +
coord_cartesian(clip = "off") +
theme(plot.margin = margin(200, 5, 5, 5)) Note that the y-scale is unpopulated because it hasn't observed any of the variables: layer_scales()$y$is_empty()
#> [1] TRUE Created on 2024-04-25 with reprex v2.1.0 I think all of this brings us to the following question: should position adjustments attempt to preserve any variables? |
Well put - that's the conclusion that I'm circling back to as well. Maybe once Maybe a better way to frame the issue is whether ggplot should signal any infos or warnings if the user accidentally mixes data-space and panel-space? Because my surprise with the reprex is more so the fact that's not obvious from the user's side that they're mixing data-space and panel-space - the code reads like it should plot the |
Yeah I agree that such warnings would be nice, but to my estimation there are a lot of places where aesthetics are combined into new ones which would mean a lot of checks scattered around the codebase. In the case of position adjustments specifically, it isn't standardised somewhere what aesthetics they read or write so it'd be hard to do systematically. Perhaps the least intrusive way out is simply to document the use of |
Got it - that sounds completely reasonable! I'm content with just the fact that this is clarified for me - I'll let you make the call for whether this also warrants an entry in the docs (and feel free to close this as complete). |
At least in GeomBar (and possibly elsewhere), when an
<AsIs>
aesthetic for bar height is parameterized, the<AsIs>
class is sometimes dropped.Here,
ymax
is stripped of<AsIs>
:This also has consequences for training of the scales.1 In the plot, the height of the shortest bar is determined only by
expansion
Expected plot of bar heights rendered in npc:
Footnotes
I'm actually torn on whether this part is also a bug. Technically, the bars are following the baseline-at-0 constraint (just that 0 is now interpreted in npc, which is meaningless). But maybe in this case GeomBar should override the baseline of the bars to always be on data scale (probably hard)? Or if users really want that for whatever reason, they could just add
ylim(0, NA)
I suppose ↩The text was updated successfully, but these errors were encountered: