如何在 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)
它应该看起来像这样:
感谢您的宝贵时间!
最佳答案
一种方法是先绘制更宽的黑色线条。请注意,您需要添加 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)
关于r - 在 geom_smooth 中更改线条边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67569889/