Skip to content

Instantly share code, notes, and snippets.

@aaronberdanier
Created May 11, 2012 19:57
Show Gist options
  • Save aaronberdanier/2662077 to your computer and use it in GitHub Desktop.
Save aaronberdanier/2662077 to your computer and use it in GitHub Desktop.
Code for pretty error clouds
xdat <- seq(0,10,.1)
ydat <- sin(xdat)
ndat <- length(xdat)
err <- rnorm(ndat,1,0.25)
err_hi <- ydat + err
err_lo <- ydat - err
plot(ydat~xdat, type="n", ylim=c(min(err_lo),max(err_hi)))
# add the error polygon
# it draws around the shape, so one half must be read backwards
polygon(c(xdat[1:ndat],xdat[ndat:1]), c(err_hi[1:ndat],err_lo[ndat:1]), col="gray66",border=NA)
lines(ydat~xdat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment