r - 在 geom_smooth 中更改线条边框颜色

标签 r ggplot2 plot data-visualization

如何在 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)

enter image description here

它应该看起来像这样:

enter image description here

感谢您的宝贵时间!

最佳答案

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

enter image description here

关于r - 在 geom_smooth 中更改线条边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67569889/

相关文章:

r - Knit 钩子(Hook)在 tex 文件中的\documentclass 行之前添加代码,以避免选项与 xcolor 冲突

r - 如何使用 Tidyverse 在 R 中聚合凌乱的季度数据,搜索第一组连续的四个季度

r - 加速大型矩阵中的索引

plot - Gnuplot - 用连续变化的线条颜色绘制图形 - 用颜色淡入淡出/过渡绘制图形

python - MatLab 到 Python 欧拉方程

matlab - MATLAB 中的 Normplot 颜色图

r - R 中具有复杂函数和 plyr 的 tryCatch

r - 使用 ggplot、gtable 和 cowplot 固定图例框的宽度

r - 按类别创建散点图,其中线条连接来自 ggplot 中相同 ID 的值

r - R 版本 3.2.2 下 arrangeGrob 的问题