-
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
Confusing warning in geom_segment()
with length 1 aesthetics
#5762
Comments
Argueably, the example you raise should also be The warning can also be surpressed by providing |
@teunbrand Using standard evaluation like in your example implies using the table name ( Thanks for the tip about warning suppressing :-) Feels a bit hacky but it works fine |
There are plenty of things that are not really pipeable for ggplot2, for example setting scale parameters, so preserving pipeability is only a minor concern. The proper way to go about this is implementing #3501 I guess, where you could arbitrarily summarise the data. |
I'm just seeing this for the first time, coming from #5797. I feel it's important to highlight what exactly is going wrong here and in #5797. While the plot may look fine, it is not. The geom that triggers the warning is drawn over and over again, as many times as the data is duplicated. You can see this if you try to make the geom transparent. We used to get bug reports about problems with transparency all the time and it was always this issue. I would strongly advise against suppressing the warning. Instead, fix the code so you actually draw only one line. @teunbrand The actionable item here is maybe to improve the warning, instead of just saying "did you mean to use annotate()". Clearly people don't understand what the issue is. library(ggplot2)
ggplot(mtcars) +
aes(x=mpg, y=disp) +
geom_point() +
geom_segment(
aes(x=min(mpg), xend=max(mpg), y=min(disp), yend=max(disp)),
alpha = 0.1, # should result in a transparent line
linewidth = 5
)
#> Warning in geom_segment(aes(x = min(mpg), xend = max(mpg), y = min(disp), : All aesthetics have length 1, but the data has 32 rows.
#> ℹ Did you mean to use `annotate()`? Created on 2024-03-24 with reprex v2.0.2 |
Yeah I agree with Claus that the warning is there for good reason.
The examples in the docs should be fixed, either by providing the data in the correct shape or using |
I think the point is that people that run into this issue generally do not want to use |
Sorry if my comment is out of line (I don't understand ggplots internals at all), but is recycling aesthetics of any length ever a good thing? |
Recycling happens following the tidyverse rules (either library(ggplot2)
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(colour = "points")) +
geom_smooth(aes(colour = "line"))
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x' Created on 2024-03-28 with reprex v2.1.0 |
Hi,
In the latest version, a warning is thrown if aesthetics are length 1 while the data is not, hinting to use
annotate()
instead of a geom.Of note, I could have missed it but I couldn't find this change in NEWS.
While this warning should be legitimate in most cases, there are some where it does not make much sense and that
annotate()
is not usable, in my case when usinggeom_segment()
with summary functions.It is thrown in the documentation (https://ggplot2.tidyverse.org/reference/aes_position.html).
One could argue that the documentation example could indeed be replaced with
annotate()
, so here is an example that cannot:Created on 2024-03-07 with reprex v2.1.0
The text was updated successfully, but these errors were encountered: