Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

r - Control transparency of smoother and confidence interval

I'm refering to this SO question from 2 years ago, with ggplot : Adjust Transparency (alpha) of stat_smooth lines, not just transparency of Confidence Interval

The first method suggested allows to set the alpha transparency of the confidence interval alone:

ggplot(head(airquality, 60), aes(x=Day, y=Temp, color=factor(Month))) +
  geom_point() + stat_smooth(method = "lm", se=TRUE, alpha=1.0)

enter image description here

The second method allows to set the alpha transparency for the line itself, but you loose the confidence interval in the meantime, even with se=TRUE:

ggplot(head(airquality, 60), aes(x=Day, y=Temp, color=factor(Month))) +
  geom_point() + geom_line(stat='smooth', method = "lm", se=TRUE, alpha=0.3)

enter image description here

My question: How to control the transparency of both the smoothing line and the confidence interval?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This calculates the model twice. But normally that shouldn't be a performance issue.

ggplot(head(airquality, 60), aes(x=Day, y=Temp, color=factor(Month))) +
  geom_point() + 
  geom_ribbon(stat='smooth', method = "lm", se=TRUE, alpha=0.1, 
              aes(color = NULL, group = factor(Month))) +
  geom_line(stat='smooth', method = "lm", alpha=0.3)

resulting plot


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...