但是,我发现在具有许多方面和可能是
2 3 4 5 6 7 8 9 | fac=rep(LETTERS[1:10], 100), x=rnorm(1000) ) ggplot(df, aes(x=x)) + geom_bar(binwidth=0.5) + facet_grid(~fac) + scale_x_continuous(formatter="percent") |

我知道我可以通过向
提供
但是,我正在处理包含许多问题和十几个交叉中断的调查数据,因此需要找到一种自动执行此操作的方法。
有没有办法告诉
编辑:理想情况下,我不想指定最小和最大点,而是以某种方式利用内置的 ggplot 刻度训练,并使用默认计算的刻度限制。
您可以在调用 ggplot 时传入诸如
2 3 4 5 6 | geom_bar(binwidth=0.5) + facet_grid(~fac) + scale_x_continuous(breaks = c(min(df$x), 0, max(df$x)) , labels = c(paste( 100 * round(min(df$x),2),"%", sep =""), paste(0,"%", sep =""), paste( 100 * round(max(df$x),2),"%", sep ="")) ) |
或使用

更新
在最新版本的 ggplot2 中,
2 3 4 5 6 7 8 9 10 11 | breaks <- c(min(x),median(x),max(x)) names(breaks) <- attr(breaks,"labels") breaks } ggplot(df, aes(x=x)) + geom_bar(binwidth=0.5) + facet_grid(~fac) + scale_x_continuous(breaks = myBreaks,labels = percent_format()) + opts(axis.text.x = theme_text(angle = 90, hjust = 1,size = 5)) |
例如:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # Compute the list of breaks using original_func, # then remove any of these that occur in remove_list remove_breaks <- function(original_func, remove_list = list()) { function(x) { original_result <- original_func(x) original_result[!(original_result %in% remove_list)] } } # Compute the list of labels using original_func, # then remove any of these that occur in remove_list remove_labels <- function(original_func, remove_list = list()) { function(x) { original_result <- original_func(x) replace(original_result, original_result %in% remove_list, '') } } # Original plot ggplot(data.frame(x=c(1,2,3,4,5,6,7,8), y = c(1,4,9,16,25,36,49,64))) + geom_line(aes(x, y)) + scale_x_continuous(breaks = scales::breaks_pretty(9), minor_breaks = scales::breaks_pretty(18), labels = scales::label_number_auto()) + scale_y_continuous(breaks = scales::breaks_pretty(9), minor_breaks = scales::breaks_pretty(18), labels = scales::label_number_auto()) # Remove some breaks from the x-axis, and remove some labels from the y-axis ggplot(data.frame(x=c(1,2,3,4,5,6,7,8), y = c(1,4,9,16,25,36,49,64))) + geom_line(aes(x, y)) + scale_x_continuous(breaks = remove_breaks(scales::breaks_pretty(9), seq(3,6)), minor_breaks = remove_breaks(scales::breaks_pretty(18), seq(3,6,0.5)), labels = scales::label_number_auto()) + scale_y_continuous(breaks = scales::breaks_pretty(9), minor_breaks = scales::breaks_pretty(18), labels = remove_labels(scales::label_number_auto(), seq(20, 30))) |
当然,使用我简单的
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow
我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle
我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r
如何在Ruby中获取BasicObject实例的类名?例如,假设我有这个:classMyObjectSystem我怎样才能使这段代码成功?编辑:我发现Object的实例方法class被定义为returnrb_class_real(CLASS_OF(obj));。有什么方法可以从Ruby中使用它? 最佳答案 我花了一些时间研究irb并想出了这个:classBasicObjectdefclassklass=class这将为任何从BasicObject继承的对象提供一个#class您可以调用的方法。编辑评论中要求的进一步解释:假设你有对象
我有一个div,它根据表单是否正确提交而改变。我想知道是否可以检查类的特定元素?开始元素看起来像这样。如果输入不正确,添加错误类。 最佳答案 试试这个:browser.div(:id=>"myerrortest").class_name更多信息:http://watir.github.com/watir-webdriver/doc/Watir/HTMLElement.html#class_name-instance_method另一种选择是只查看具有您期望的类的div是否存在browser.div((:id=>"myerrortes
我在非Rails项目中使用ActiveRecord。在Rails中,我可以这样做:config.time_zone='EasternTime(US&Canada)'config.active_record.default_timezone='EasternTime(US&Canada)'但如果我不使用rails,我该如何设置时区? 最佳答案 ActiveRecord::Base.default_timezone='EasternTime(US&Canada)' 关于ruby-没有轨道的A