简体   繁体   中英

Change line border color in geom_smooth

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)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM