I would like to plot shaded confidence regions for various lines, but would like the alpha level in these regions to vary gradually from b to c, where b is the alpha at the median, and c is the alpha at whatever outer quantile I am using. The following code generates a line and confidence region plot as I would like, but without the variable transparency.
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)
You can overplot 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)
}
Altough, I think your example is actually wrong, and probably want 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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With