【问题标题】:Change line border color in geom_smooth更改 geom_smooth 中的线条边框颜色
【发布时间】:2021-08-06 17:27:22
【问题描述】:

如何改变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)

它应该看起来像这样:

感谢您的宝贵时间!

【问题讨论】:

标签: r ggplot2 plot data-visualization


【解决方案1】:

一种方法是先绘制更宽的黑线。请注意,您需要添加 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)

【讨论】:

  • 如果想改变置信区间区域外边界的颜色怎么办?
  • @Dag 添加+ geom_ribbon(stat = "smooth", method = "lm", fill = NA, color = "black")
猜你喜欢
  • 1970-01-01
  • 2016-11-07
  • 2010-12-25
  • 1970-01-01
  • 2017-08-03
  • 1970-01-01
  • 2017-03-05
  • 1970-01-01
相关资源
最近更新 更多