本文介绍了如何突出两条线之间的区域? ggplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有包含变量的数据框,它是conf。间隔
时间x x.upper x.lower
1 1.00 0.91 1.11
2 1.03 0.92 1.13
3 1.03 0.95 1.17
2 1.06 0.90 1.13
ggplot
它:
library(ggplot2)
ggplot(data = df,aes (time,x))+
geom_line(aes(y = x.upper),color ='red')+
geom_line(aes(y = x.lower),color ='blue') +
geom_line()
我想突出显示红线和蓝线之间的区域,到 geom_smooth()
函数。
ggplot(data = df,aes(time,x))+
geom_ribbon(aes(x = time ,ymax = x.upper,ymin = x.lower),fill =pink,alpha = .5)+
geom_line(aes(y = x.upper),color ='red')+
geom_line(aes(y = x.lower),color ='blue')+
geom_line()
I have data frame containing variable and it's conf. interval
time x x.upper x.lower
1 1.00 0.91 1.11
2 1.03 0.92 1.13
3 1.03 0.95 1.17
2 1.06 0.90 1.13
I ggplot
it:
library(ggplot2)
ggplot(data = df,aes(time,x))+
geom_line(aes(y = x.upper), colour = 'red') +
geom_line(aes(y = x.lower), colour = 'blue')+
geom_line()
I want to highlight area between red and blue lines, smth similar to geom_smooth()
function. How can I do it?
解决方案
A geom_ribbon
is exactly what you need
ggplot(data = df,aes(time,x))+
geom_ribbon(aes(x=time, ymax=x.upper, ymin=x.lower), fill="pink", alpha=.5) +
geom_line(aes(y = x.upper), colour = 'red') +
geom_line(aes(y = x.lower), colour = 'blue')+
geom_line()
这篇关于如何突出两条线之间的区域? ggplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!