How does one change the color of the line border in geom_smooth()?
library(ggplot2)
mtcars$cyl <- as.factor(mtcars$cyl)
ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, shape=cyl)) +
geom_point() +
geom_smooth(method=lm)

It should look something like this:

Thank you for your time!
One way is to plot wider, black lines first. Note that you need to add group = cyl for this to work properly.
ggplot(mtcars, aes(x=wt, y=mpg, group = cyl, color = cyl)) +
geom_point() +
geom_smooth(method = lm, size = 2.5, color = "black", se = FALSE) +
geom_smooth(method = lm)

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