Skip to content

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

Closed as not planned
@ptoche

Description

@ptoche

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions