Return call from ggplot object

Posted by aL3xa on Stack Overflow See other posts from Stack Overflow or by aL3xa
Published on 2010-05-04T11:20:32Z Indexed on 2010/05/05 4:58 UTC
Read the original article Hit count: 261

Filed under:
|

I've been using ggplot2 for a while now, and I can't find a way to get formula from ggplot object. Though I can get basic info with summary(<ggplot_object>), in order to get complete formula, usually I was combing up and down through .Rhistory file. And this becomes frustrating when you experiment with new graphs, especially when code gets a bit lengthy... so searching through history file isn't quite convenient way of doing this... Is there a more efficient way of doing this? Just an illustration:

p <- qplot(data = mtcars, x = factor(cyl), geom = "bar", fill = factor(cyl)) + 
     scale_fill_manual(name = "Cylinders", value = c("firebrick3", "gold2", "chartreuse3")) + 
     stat_bin(aes(label = ..count..), vjust = -0.2, geom = "text", position = "identity") + 
     xlab("# of cylinders") + ylab("Frequency") + 
     opts(title = "Barplot: # of cylinders")

I can get some basic info with summary:

> summary(p)
data: mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb [32x11]
mapping:  fill = factor(cyl), x = factor(cyl)
scales:   fill 
faceting: facet_grid(. ~ ., FALSE)
-----------------------------------
geom_bar:  
stat_bin:  
position_stack: (width = NULL, height = NULL)

mapping: label = ..count.. 
geom_text: vjust = -0.2 
stat_bin: width = 0.9, drop = TRUE, right = TRUE 
position_identity: (width = NULL, height = NULL)

But I want to get code I typed in to get the graph. I reckon that I'm missing something essential here... it's seems impossible that there's no way to get call from ggplot object!

© Stack Overflow or respective owner

Related posts about r

    Related posts about ggplot2