I'm plotting some data using geom_smooth and looking for a way to change the color of the standard error shading for each line to match that line (ie., a red line would have it's standard error shaded red).
I've looked through the official ggplot2 documentation as well as the list of opts() at https://github.com/hadley/ggplot2/wiki/%2Bopts%28%29-List.
Any advice (or just confirmation of whether or not it's possible) is appreciated.
The grey area [SE=TRUE] would be a zone that covers 95% confidence level [that the values will be within that area]. https://ggplot2.tidyverse.org/reference/geom_smooth.html [Level=95% by default, can be increased to 99%].
The warning geom_smooth() using formula 'y ~ x' is not an error. Since you did not supply a formula for the fit, geom_smooth assumed y ~ x, which is just a linear relationship between x and y.
stat_smooth: Add a smoother.Aids the eye in seeing patterns in the presence of overplotting.
Your (understandable) mistake is to think that you should be changing the color rather than the fill. The standard error shadings are made with geom_ribbon
essentially, and they are a 2d area, so the "color" they are "filled" with is determined by fill
, not colour
.
Try:
geom_smooth(aes(...,fill = variable))
where variable is the same one you map to colour elsewhere.
If you have multiple groups you simple define color = Vars
and group = Vars
within ggplot(aes())
, and then additional aes(fill = Vars)
within geom_smooth(aes(fill = Species))
. (Based on answer here)
Dummy example:
# Make confidence intervals the same color as line by group ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, group = Species, color = Species)) + geom_point() + geom_smooth(aes(fill = Species)) # additional `aes()` referencing to confidence interval as a `fill` not as a `color`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With