gpt4 book ai didi

R 图跳跃置信区域

转载 作者:行者123 更新时间:2023-12-04 11:08:09 26 4
gpt4 key购买 nike

我正在尝试创建一个置信区间图,该图每年都会更新。

这是我试图创建的情节的一个例子:
graph from excel

一些可重现的数据如下:

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

当我尝试绘制线条时,我收到一个关于长度不匹配的错误。我猜这与 NA 值有关。我不知道该怎么做,所以任何帮助将不胜感激。另一个问题是填充字里行间。

这甚至可能吗?

最佳答案

可以通过 geom_ribbon() 实现.

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

关于R 图跳跃置信区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54912515/

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