Skip to content

Conversation

@teunbrand
Copy link
Collaborator

This PR aims to fix #6551.

Briefly, we allow setting the colour/linetype/linewidth of the confidence bands in geom_smooth().
A demonstration:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

ggplot(mpg, aes(displ, hwy, fill = drv)) +
  geom_smooth(
    band.colour = "black",
    band.linetype = 3,
    band.linewidth = 0.5
  )
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Created on 2025-09-26 with reprex v2.1.1

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR, there would be no way to synchronise the look of the outer bands with the central one, right?

@teunbrand
Copy link
Collaborator Author

That's right. Do you think missing parameters should be drawn from the central line?

@thomasp85
Copy link
Member

That is how we do it for the others, right? NULL means don't draw, NA means inherit..?

@teunbrand
Copy link
Collaborator Author

I think the meaning of NULL and NA are swapped. The main reason I initially didn't take properties from the central line was because it should be hidden by default. Of course we might achieve that by setting transparent colours, 0 linewidth or blank linetypes.

@thomasp85
Copy link
Member

oh, yeah you are right... Then just default the arguments to NA to ensure default is not to draw, and let NULL mean inherit

Merge branch 'main' into geom_smooth_band_gp

# Conflicts:
#	man/geom_smooth.Rd
@teunbrand
Copy link
Collaborator Author

I'm now hiding it with band.linetype = "blank". Activating the band lines requires setting a non-blank linetype.

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

ggplot(mpg, aes(displ, hwy)) +
  geom_smooth(band.linetype = 1, linetype = 2)
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

band.linetype = NULL inherits from center line.

ggplot(mpg, aes(displ, hwy)) +
  geom_smooth(band.linetype = NULL, linetype = 2)
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Created on 2025-12-04 with reprex v2.1.1

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

Successfully merging this pull request may close these issues.

Feature Request:Add some parameters to geom_smooth to adjust the properties of the lines at the edges of the confidence intervals.

2 participants