更改 geom_smooth 中的线边框颜色

mva*_*man 3 plot r data-visualization ggplot2

如何改变 中线条边框的颜色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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

它应该看起来像这样:

在此输入图像描述

感谢您的时间!

Lat*_*row 5

一种方法是先绘制更宽的黑线。请注意,您需要添加group = cyl才能使其正常工作。

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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • @Dag 添加 `+ geom_ribbon(stat = "smooth", method = "lm", fill = NA, color = "black")` (4认同)
  • 如果想要更改置信区间区域的外边界的颜色怎么办? (2认同)