Shading of the confidence area with graded alpha (transparency)

I would like to build shaded areas of confidence for different lines, but I would like the alpha level in these regions to gradually change from b to c, where b is the alpha environment, and c is alpha for any external quantile I use. The following code generates a line graph and confidence, as I would like, but without the transparency of the variable.

x= 1:10+rnorm(10)
xhigh=x+rnorm(10)^2
xlow=x-rnorm(10)^2

plot(x,type='l')
polygon(x=c(1:length(xlow),length(xlow):1),   y=c(xhigh,xlow[length(xlow):1]),col = rgb(1,0,0,.1),border=NA)
+4
source share
1 answer

You can overlap many polygons:

plot(x,type='l')
for (i in seq(0, 1, 0.01)) {
  polygon(x = c(x + i * (xhigh - x), x - i * (xlow - x)), 
          col = rgb(1, 0, 0, .005), border = NA)
}

enter image description here

Although, I think your example is actually erroneous and probably wants something like:

plot(x,type='l')
for (i in seq(0, 1, 0.01)) {
  polygon(x = c(1:10, 10:1),
          y = c(x + i * (xhigh - x), rev(x - i * abs(x - xlow))), 
          col = rgb(1, 0, 0, .005), border = NA)
}

enter image description here

+5
source

Source: https://habr.com/ru/post/1667648/


All Articles