Skip to content

geom_smooth() drops variables from plot but not from legend #3363

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

Closed
ptoche opened this issue Jun 13, 2019 · 3 comments
Closed

geom_smooth() drops variables from plot but not from legend #3363

ptoche opened this issue Jun 13, 2019 · 3 comments
Labels
feature a feature request or enhancement guides 📏

Comments

@ptoche
Copy link

ptoche commented Jun 13, 2019

The se fill when variable factor(gear) is equal to 5 is dropped from the plot, but still appears in the legend. I think it should be dropped from the legend too.

``` r
library(reprex)
library(ggplot2)
#> Registered S3 methods overwritten by 'ggplot2':
#>   method         from 
#>   [.quosures     rlang
#>   c.quosures     rlang
#>   print.quosures rlang
ggplot(data = mtcars, aes(x = mpg, y = disp)) +
    geom_smooth(aes(fill = factor(gear))) 
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : span too small. fewer data values than degrees of freedom.
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : pseudoinverse used at 14.923
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : neighborhood radius 4.777
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : reciprocal condition number 0
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : There are other near singularities as well. 116.14
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : Chernobyl! trL>n 5

#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : Chernobyl! trL>n 5
#> Warning in sqrt(sum.squares/one.delta): NaNs produced
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : span too small.
#> fewer data values than degrees of freedom.
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used
#> at 14.923
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius
#> 4.777
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : reciprocal
#> condition number 0
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : There are other
#> near singularities as well. 116.14
#> Warning in stats::qt(level/2 + 0.5, pred$df): NaNs produced
```

![](https://i.imgur.com/Zmj00Yk.png)

<sup>Created on 2019-06-14 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>
@ptoche
Copy link
Author

ptoche commented Jun 13, 2019

Plot not showing above for some reason, so here:

@paleolimbot
Copy link
Member

The legend does not use the layer data, only the scales and the draw_key from the geometry. I think that changing the code to enable this would probably be a lot of work.

@paleolimbot paleolimbot added feature a feature request or enhancement guides 📏 labels Jun 18, 2019
@teunbrand
Copy link
Collaborator

I think discussion about smarter guide/layer interactions should be continued in #3648.

However, geom_smooth() doesn't drop that fill level at all. It just sets the ymin/ymax aesthetics to NA because the standard error couldn't be calculated. So even if we would get guides to be smarter, it is still unlikely that this case can be detected. I don't think it is currently worth it to special-case such situation.

@teunbrand teunbrand closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement guides 📏
Projects
None yet
Development

No branches or pull requests

3 participants