Skip to content

Instantly share code, notes, and snippets.

@kohske
Created May 22, 2011 13:49
Show Gist options
  • Save kohske/985482 to your computer and use it in GitHub Desktop.
Save kohske/985482 to your computer and use it in GitHub Desktop.
ggplot return object with stat and geom name.
g <- ggplot(mtcars, aes(cyl, mpg)) + geom_point() + stat_summary(fun.y=mean, geom="line")
d <- print(g)
## look up data from "stat"
get_data_from_stat <- function(gobj, stat) Find(function(x)attr(x, "stat")==stat, gobj$data)
## look up data from "geom"
get_data_from_geom <- function(gobj, geom) Find(function(x)attr(x, "geom")==geom, gobj$data)
get_data_from_stat(d, "summary")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment