r - Shading confidence intervals manually with ggplot2 -
i have manually created data set of life expectancies accompanying 95% confidence bands. plot these on time scale prefer bands shaded rather dotted lines. code shown:
p1 = ggplot() p2 = p1 + geom_line(aes(x=pl$time, y=pl$menle), colour="blue") p3 = p2 + geom_line(aes(x=pl$time, y=pl$menlelb), colour="blue", lty="dotted") p4 = p3 + geom_line(aes(x=pl$time, y=pl$menleub), colour="blue", lty="dotted")
is there simple way shade interval rather have lines?? if i'm missing simple apologise in advance cannot find indicate simple way of doing this.
it helpful if provided own data, think following after.
first, create dummy data:
##i presume lb , ub lower/upper bound pl = data.frame(time = 0:10, menle = rnorm(11)) pl$menlelb = pl$menle -1 pl$menleub = pl$menle +1
then create plot. shaded region created using geom_ribbon
:
ggplot(pl, aes(time)) + geom_line(aes(y=menle), colour="blue") + geom_ribbon(aes(ymin=menlelb, ymax=menleub), alpha=0.2)
Comments
Post a Comment