从 ggplot 对象返回调用

aL3*_*3xa 5 r ggplot2

我已经使用了ggplot2一段时间了,但我找不到从ggplot对象获取公式的方法。虽然我可以通过 获取基本信息summary(<ggplot_object>),但为了获得完整的公式,通常我会上下梳理.Rhistory文件。当您尝试新图表时,这会变得令人沮丧,尤其是当代码变得有点长时......因此搜索历史文件并不是很方便的方法......有没有更有效的方法来做到这一点?只是一个例子:

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")
Run Code Online (Sandbox Code Playgroud)

我可以通过以下方式获取一些基本信息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)
Run Code Online (Sandbox Code Playgroud)

但我想获取我输入的代码来获取图表。我认为我在这里错过了一些重要的东西......似乎不可能没有办法从ggplot对象中获得调用!

had*_*ley 5

目前不可能从 ggplot2 对象转到(可能)创建它的代码。