我已经使用了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 = …Run Code Online (Sandbox Code Playgroud)