gpt4 book ai didi

r - 如何突出显示两行之间的区域? ggplot

转载 作者:行者123 更新时间:2023-12-04 10:00:14 25 4
gpt4 key购买 nike

我有包含变量的数据框,它是conf。间隔

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

ggplot它:
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()

我想突出显示红线和蓝线之间的区域,类似于 geom_smooth()函数。我该怎么做?

最佳答案

geom_ribbon正是您需要的

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()

enter image description here

关于r - 如何突出显示两行之间的区域? ggplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24419574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com