Comments (4)
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 I()
as 'at your own risk' and point out potential interactions with stats and position adjustments that may go unexpected.
from ggplot2.
Thanks June!
I think the following things are happening.
position_stack()
is doing a computation onymax
that drops the class. The data come out the correct way fromGeomBar$setup_data
andposition = "identity"
preserves the class.- The scales are supposed to ignore class vectors, as that is the main mechanism through which this works. The y scale gets trained to
c(0.5, 2)
because it only observes the plainymax
returned from the position adjustment. I don't think the scale range should include 0 in this case, as y variables are . Theoretically, the y scale shouldn't even be populated in this case as it is supposed to ignore all y variables.
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?
While I'm still undecided, I'm leaning towards 'no' as these are designed to operate in data-space and mixing data-space and panel-space in these computations is prone to unexpected results (better to not promise anything, than promising and not delivering).
from ggplot2.
better to not promise anything, than promising and not delivering
Well put - that's the conclusion that I'm circling back to as well. Maybe once I()
gets more widely used people will start developing stronger intuitions about what they expect here, but as it stands I'm now less sure about the "expected output" I posed originally.
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 y
only in panel-space (setting aside the issue of whatever that should mean for GeomBar) but Position introduces data-space positioning internally and causes the mixing.
from ggplot2.
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).
from ggplot2.
Related Issues (20)
- Release ggplot2 3.5.1
- custom guide with `theme_void()` will throw a warning message HOT 1
- VSCode and ggplot (randomly) throw error "Error in UseMethod("depth")". HOT 7
- Feature request: flexible parametrisation of rectangles
- Cryptic error when mis-specifying linetype HOT 6
- Version 3.5.0 or 3.5.1 cannot render a plot made with 3.4.4 HOT 2
- Standardising calls to `gpar()`
- Fill and color guides for factor with `drop=FALSE` don't show color. HOT 8
- `guide_coloursteps(show.limits = T)` produces strange lower limit HOT 1
- Warnings due to partial matching HOT 2
- Reproducible example for `position_jitter()` not working HOT 1
- geom_sf_label() returns an error HOT 3
- date_breaks and date_breaks minor don't check argument type HOT 2
- `scale_*_*` `labels` argument often doesn't work as expected with a function HOT 8
- geom_histogram produces wrong number of bins in special cases HOT 2
- x/ylim Arguments in coord_fixed Donβt Seem to Be Applied to Contours: HOT 1
- Feature request: allow adding aesthetics together HOT 2
- Adding bootstrap customization for stat_summary(fun.data="mean_cl_boot") HOT 1
- Have header font be part of theme specification HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggplot2.