Remove a layer from a ggplot2 chart

Posted by Erik Shilts on Stack Overflow See other posts from Stack Overflow or by Erik Shilts
Published on 2012-11-15T22:18:30Z Indexed on 2012/11/15 23:00 UTC
Read the original article Hit count: 235

Filed under:
|

I'd like to remove a layer (in this case the results of geom_ribbon) from a ggplot2 created grid object. Is there a way I can remove it once it's already part of the object?

library(ggplot2)
dat <- data.frame(x=1:3, y=1:3, ymin=0:2, ymax=2:4)
p <- ggplot(dat, aes(x=x, y=y)) + geom_ribbon(aes(ymin=ymin, ymax=ymax), alpha=0.3) 
     + geom_line()

# This has the geom_ribbon
p

# This overlays another ribbon on top
p + geom_ribbon(aes(ymin=ymin, ymax=ymax, fill=NA))

© Stack Overflow or respective owner

Related posts about r

    Related posts about ggplot2