Skip to content

layer does not work as expected for creating a geom_smooth plot #5572

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
davidhodge931 opened this issue Dec 8, 2023 · 3 comments · Fixed by #5700
Closed

layer does not work as expected for creating a geom_smooth plot #5572

davidhodge931 opened this issue Dec 8, 2023 · 3 comments · Fixed by #5700

Comments

@davidhodge931
Copy link

library(tidyverse)
library(palmerpenguins)

penguins |>
  ggplot(aes(x = flipper_length_mm,
             y = body_mass_g,)) +
  geom_smooth()
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
#> Warning: Removed 2 rows containing non-finite outside the scale range
#> (`stat_smooth()`).

penguins |>
  ggplot(aes(x = flipper_length_mm,
             y = body_mass_g,)) +
layer(
  geom = ggplot2::GeomSmooth,
  stat = "smooth",
  position = ggplot2::position_identity()
)
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
#> Warning: Removed 2 rows containing non-finite outside the scale range
#> (`stat_smooth()`).

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

@teunbrand
Copy link
Collaborator

It needs the parameter se = TRUE to show the standard error, i.e.:

penguins |>
  ggplot(aes(x = flipper_length_mm,
             y = body_mass_g,)) +
  layer(
    geom = ggplot2::GeomSmooth,
    stat = "smooth",
    position = ggplot2::position_identity(),
    params = list(se = TRUE)
  )

@davidhodge931
Copy link
Author

Is it possible that GeomSmooth could default to se = TRUE to match what we see in geom_smooth?

@teunbrand
Copy link
Collaborator

teunbrand commented Jan 3, 2024

I'm not sure that would be wise, as I think there is the possibility that geom_smooth() may be uses with a stat that isn't StatSmooth and doesn't produce the ymin/ymax and xmin/ymax variables. However, I see no reason why the default couldn't be NULL and gets resolved based on whether those columns are present in the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants