从ggplot对象返回调用 [英] Return call from ggplot object

查看:127
本文介绍了从ggplot对象返回调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 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(圆柱体数量)+ ylab(Frequency)+
opts( title =Barplot:气瓶数量)

我可以用 summary

 >摘要(p)
数据:mpg,cyl,disp,hp,drat,wt,qsec,vs,am,gear,carb [32x11]
mapping:fill = factor(cyl),x = factor (cyl)
scale:填充
faceting:facet_grid(。〜。,FALSE)
---------------------- -------------
geom_bar:
stat_bin:
position_stack:(width = NULL,height = NULL)

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

但我想要输入代码来获取图形。我认为我错过了一些重要的东西......看起来不可能的是,没有办法从 ggplot 对象获得调用!


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!

解决方案

It's not currently possible to go from a ggplot2 object to the code that (might have) created it.

这篇关于从ggplot对象返回调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆