我想即兴创作与密度成正比的回归图阴影。例如,置信区间窄则阴影浓,而置信区间宽则填充颜色浅。结果图可能如下所示:
这是一个工作示例:
set.seed(1234)
md <- c(seq(0.01, 1, 0.01), rev(seq(0.01, 1, 0.01)))
cv <- c(rev(seq(0.01, 1, 0.01)), seq(0.01, 1, 0.01))
rv <- rnorm (length(md), 0.1, 0.05)
df <- data.frame(x =1:length(md), F = md*2.5 + rv, L =md*2.5 -rv-cv, U =md*2.5+ rv+ cv)
plot(df$x, df$F, ylim = c(0,4), type = "l")
polygon(c(df$x,rev(df$x)),c(df$L,rev(df$U)),col = "cadetblue", border = FALSE)
lines(df$x, df$F, lwd = 2)
#add red lines on borders of polygon
lines(df$x, df$U, col="red",lty=2)
lines(df$x, df$L, col="red",lty=2)