As is any method to use geom_ribbon in cycle. I try, but meet a problem. This is my try:
library(ggplot2)
# Create data
huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
m <- 1500 #weight of shadow-line
#Base graph
h <- ggplot(huron, aes(year))+geom_line(aes(x=year, y=level), color='blue')+theme_bw()
count <- 5 # count shadow-lines
start_alpha <- 0.1 # Initial aplha
p <-h
for (i in 0:count-1)
{
p <- p +
geom_ribbon(aes(ymin=level-(level/m)*i, ymax=level-(level/m)*(i+1)), alpha=start_alpha-(start_alpha/count)*i, fill='blue')
}
print(p)
I investigate the result. It seems that i-cycle variable not used by value, but used as pointer. Look at this:
i <- 0
print(p)
i <- 1
print(p)