Adjust Transparency (alpha) of stat_smooth lines, not just transparency of Confidence Interval

人盡茶涼 提交于 2019-12-02 18:49:20

To set alpha value just for the line you should replace stat_smooth() with geom_line() and then inside the geom_line() use the same arguments as in stat_smooth() and additionally add stat="smooth".

ggplot(df, aes(x=x, y=value, color=variable)) +
  geom_point(size=2) +
  geom_line(stat="smooth",method = "lm", formula = y ~ 0 + I(1/x) + I((x-1)/x),
              size = 1.5,
              linetype ="dashed",
              alpha = 0.5)

As an alternative that's slightly more intuitive -- perhaps created since this answer -- you can use stat_smooth (geom="line"). The SE envelope disappears, though you can add it back with something like:

geom_smooth (alpha=0.3, size=0, span=0.5) stat_smooth (geom="line", alpha=0.3, size=3, span=0.5) +

The first line creates the SE. with no (0-width) line, and the second line adds the line over top of it. The (current) documentation mentions that stat_smooth is for non-standard geoms (e.g. "line").

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!