r - R图跳跃置信区域
问题描述
我正在尝试创建一个每年更新的置信带图。
一些可重现的数据如下:
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))
推荐阅读
- react-native - 使用 React Native 进行图像识别
- css - 具有平滑度 css 的背景形状
- python - 傅里叶逆变换不给出初始图像
- excel - VBScript 不会将复制的 Excel 插入特定页面上的 Word
- java - 如何在 Mongock 迁移后启动 Hazelcast?
- r - 从R中的BW图像中删除小形状
- r - 代码独立工作,但不是函数
- msbuild - MSBuild props 文件在由 nuget 包导入时不会被评估,但在手动导入时有效
- node.js - Gatsby x 构建时出现内容错误,gatsby-node.js 出现问题
- flutter - 如何通过 Gridview onClick 转到 Flutter 中的各个屏幕