R图跳跃置信域

R图跳跃置信域,r,ggplot2,R,Ggplot2,我正在尝试创建一个信心带图,它每年都会更新 下面是我试图创建的绘图示例: 以下是一些可复制的数据: x_axis <- seq(1,24) confidence_low_yr_1 <- c(seq(40,by=15, length.out = 12),rep(NA,12)) confidence_high_yr_1 <- c(seq(140,by=15, length.out = 12),rep(NA,12)) confidence_low_yr_2 <- c(rep(

我正在尝试创建一个信心带图,它每年都会更新

下面是我试图创建的绘图示例:

以下是一些可复制的数据:

x_axis <- seq(1,24)
confidence_low_yr_1 <- c(seq(40,by=15, length.out = 12),rep(NA,12))
confidence_high_yr_1 <- c(seq(140,by=15, length.out = 12),rep(NA,12))
confidence_low_yr_2 <- c(rep(NA,11),seq(250,by=15, length.out = 13))
confidence_high_yr_2 <- c(rep(NA,11),seq(315,by=15, length.out = 13))

x\u轴可以通过
geom\u ribbon()
实现

库(ggplot2)
x_轴

你能分享你试过的代码吗?看看goem_ribbon()如果你使用过ggplot,这是非常简单的。如果有很多年,你可以避免每次都键入
geom_ribbon
行,然后使用
ggplot(数据,aes(x=x_轴))+Map(函数(l,h)geom_ribbon(aes(ymin=l,ymax=h)),数据一次性完成[grep('confidence_low',name(data))],data[grep('confidence_high',name(data))])
library(ggplot2)

x_axis <- seq(1,24)
confidence_low_yr_1 <- c(seq(40,by=15, length.out = 12),rep(NA,12))
confidence_high_yr_1 <- c(seq(140,by=15, length.out = 12),rep(NA,12))
confidence_low_yr_2 <- c(rep(NA,11),seq(250,by=15, length.out = 13))
confidence_high_yr_2 <- c(rep(NA,11),seq(315,by=15, length.out = 13))

data = data.frame(x_axis = x_axis,confidence_low_yr_1 = confidence_low_yr_1,confidence_high_yr_1 = confidence_high_yr_1,confidence_low_yr_2 = confidence_low_yr_2,confidence_high_yr_2 = confidence_high_yr_2 )

ggplot(data, aes(x = x_axis))+
  geom_ribbon(aes(ymin = confidence_low_yr_1,ymax = confidence_high_yr_1))+
  geom_ribbon(aes(ymin = confidence_low_yr_2,ymax = confidence_high_yr_2))
graphics.off()
plot(1,
     xlim = range(x_axis),
     ylim = range(c(confidence_high_yr_1,
                    confidence_high_yr_2,
                    confidence_low_yr_1,
                    confidence_low_yr_2),
                  na.rm = TRUE),
     type = "n")
lines(x_axis, confidence_high_yr_1)
lines(x_axis, confidence_high_yr_2)
lines(x_axis, confidence_low_yr_1)
lines(x_axis, confidence_low_yr_2)