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

Unnecessary(?) warning about the size aesthetic being passed to geom_smooth() #5185

Closed
rossellhayes opened this issue Feb 8, 2023 · 1 comment

Comments

@rossellhayes
Copy link

When rendering a plot with a geom_smooth() geom and a size aesthetic, I get a warning message that using size for lines has been deprecated and that the size aesthetic is being dropped. In the past, geom_smooth() ignored the size aesthetic without generating any warnings. Is it necessary to generate a warning in this case, given the behavior has not changed from past versions?

library(ggplot2)
ggplot(mtcars, aes(x = hp, y = mpg, size = cyl)) +
    geom_point() +
    geom_smooth()
#> Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
#> ℹ Please use `linewidth` instead.
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
#> Warning: The following aesthetics were dropped during statistical transformation: size
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#>   the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#>   variable into a factor?

Created on 2023-02-08 with reprex v2.0.2

@clauswilke
Copy link
Member

In the past geom_smooth() ignored the size aesthetic by accident, due to this bug: #3250
In fact, the second warning you get, "The following aesthetics were dropped ...", informs you that size was dropped purely because it is not constant across the group, which is usually a sign that something has gone wrong. This warning is also new since the latest ggplot release.

The correct way of addressing both warnings is to supply the size aesthetic only to geom_point().

library(ggplot2)
ggplot(mtcars, aes(x = hp, y = mpg)) +
  geom_point(aes(size = cyl)) +
  geom_smooth()
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Created on 2023-02-08 with reprex v2.0.2

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

No branches or pull requests

2 participants