首页 \ 问答 \ 使用条形图分组x轴(group x axis using barplot)

使用条形图分组x轴(group x axis using barplot)

这是我的数据(data.txt):

    S1    S2   S3    S4   S5   S6    S7   S8    S9   S10  S11
T1  1.6   17   2.2   1    4.4  23.8  0.2  2.8   3.2  0.4  18.2
T2  0     3.5  1.5   0.5  4    3     6.5  21.6  0.5  1    18.6
T3  0     0    0     4.2  4.2  41.7  4.2  0     8.3  4.2  4.2
T4  4     0    0     0    0    12    4    4     4    16   20
T5  31.3  6.3  12.5  0    0    12.5  0    0     6.3  0    0
T6  12.5  0    0     18.8 0    12.5  0    0     6.3  6.3  0

这是我的代码:

data =  read.table("C:/Users/Irwan/Desktop/graph_plot/data.txt", header = TRUE, sep = "\t", row.names = 1)

attach(data)

column = colnames(data)
rows = rownames(data)

x = barplot(as.matrix(data), xaxt = "n", beside = TRUE, legend = rows, ylim = c(0, 50), density = c(30,30,30,30,70,100), angle = c(0,45,90,135,0,0))

label = as.vector(column)

text(x = x + 1.20, y = -1.25, xpd = TRUE, cex = 0.6, srt = 90, label, pos = 2)

不幸的是,我无法正确分组x轴标签。

我尝试了很多解决方案,这是我到目前为止所得到的。 任何人都可以指导我如何将结果分组到每6个柱上(例如:前6个柱的S1)。 请注意我在R中不是很好,我只能使用预装的R包,因为不知道原因我无法安装任何新包。 谢谢。

更新

我稍微改变了一下我的代码,以便它可以很容易地重现。 我的新代码:

y = matrix (1:15, ncol = 5)

x = barplot(as.matrix(y), xaxt = "n", beside = TRUE, legend = c("T1","T2","T3"), ylim = c(0,30), density = c(30,30,30), angle = c(0,45,90))

label = rep(c("S1","S2","S3","S4","S5"), each = 3)

text(x = x + 0.4, y = -1.25, xpd = TRUE, cex = 0.6, srt = 90, label, pos = 2)

This is my data (data.txt):

    S1    S2   S3    S4   S5   S6    S7   S8    S9   S10  S11
T1  1.6   17   2.2   1    4.4  23.8  0.2  2.8   3.2  0.4  18.2
T2  0     3.5  1.5   0.5  4    3     6.5  21.6  0.5  1    18.6
T3  0     0    0     4.2  4.2  41.7  4.2  0     8.3  4.2  4.2
T4  4     0    0     0    0    12    4    4     4    16   20
T5  31.3  6.3  12.5  0    0    12.5  0    0     6.3  0    0
T6  12.5  0    0     18.8 0    12.5  0    0     6.3  6.3  0

And this is my code:

data =  read.table("C:/Users/Irwan/Desktop/graph_plot/data.txt", header = TRUE, sep = "\t", row.names = 1)

attach(data)

column = colnames(data)
rows = rownames(data)

x = barplot(as.matrix(data), xaxt = "n", beside = TRUE, legend = rows, ylim = c(0, 50), density = c(30,30,30,30,70,100), angle = c(0,45,90,135,0,0))

label = as.vector(column)

text(x = x + 1.20, y = -1.25, xpd = TRUE, cex = 0.6, srt = 90, label, pos = 2)

Unfortunately, I'm not able to group x-axis labels correctly.

I've try numbers of solution and this is what I get so far. Can anyone guide me on how to group the result on every 6 bars (example: S1 for the first 6 bars). Please bear in my that I'm not very good in R and I only able to use pre-installed R package as I cannot install any new package due to unknown reason. Thank you.

UPDATED

I have change little bit my code so that it might be easy to reproduce. My new code:

y = matrix (1:15, ncol = 5)

x = barplot(as.matrix(y), xaxt = "n", beside = TRUE, legend = c("T1","T2","T3"), ylim = c(0,30), density = c(30,30,30), angle = c(0,45,90))

label = rep(c("S1","S2","S3","S4","S5"), each = 3)

text(x = x + 0.4, y = -1.25, xpd = TRUE, cex = 0.6, srt = 90, label, pos = 2)

原文:https://stackoverflow.com/questions/29120229
更新时间:2023-07-23 12:07

最满意答案

请将您的代码包装在Ember.run.next中 。 喜欢这个:

savePost: function() {

    this.set('isProcessing', true);
    Em.run.next(this, function() {
        //just some synchronous code that takes some time (the time inbetween the two alerts)
        var i=0,a;
        alert('start code');
        while (i++ < 10000000) {
            a = Math.pow(i, Math.pow(1/i, Math.sin(i)))/3/4/5/5 * Math.log(i);
        }
        this.set('isProcessing', false);
        alert('finished code');
    }); 
}

它按预期工作。 我认为你的问题是你将isProcessing设置为true然后立即将其设置为false ,因为你不等待异步代码/ promises完成。 在这种情况下,您必须在解析promises时将isProcessing设置为false。 如果这只是一个promise,你可以在isProcessing .then()中将isProcessing设置为false ,例如:

myModel.get('children').then (children) =>
  @set 'isProcessing', false

或者,如果你解决了多个promise,或者你在循环中解析了promises,你可以使用Ember.run.debounce ,它会在最后一次调用此方法后的XXXms之后触发,例如:

finishProcessing: ->
  @set 'isProcessing', false

actions:
  savePost: ->
    myModel.get('children').then (children) =>
      children.forEach (child) =>
        child.then (resolvedChild) =>
          Ember.run.debounce @, 'finishProcessing', 500

Please wrap your code in Ember.run.next. Like this:

savePost: function() {

    this.set('isProcessing', true);
    Em.run.next(this, function() {
        //just some synchronous code that takes some time (the time inbetween the two alerts)
        var i=0,a;
        alert('start code');
        while (i++ < 10000000) {
            a = Math.pow(i, Math.pow(1/i, Math.sin(i)))/3/4/5/5 * Math.log(i);
        }
        this.set('isProcessing', false);
        alert('finished code');
    }); 
}

It works as intended. I think your problem is that you set isProcessing to true and then immediately set it to false, because you don't wait for async code/promises to complete. In this case you have to set isProcessing to false when promises are resolved. If this is only one promise you can set isProcessing to false inside .then(), for example:

myModel.get('children').then (children) =>
  @set 'isProcessing', false

Or if you resolve multiple promises, or you resolve promises inside a loop, you can use Ember.run.debounce which will fire after XXXms after last call to this method, for example:

finishProcessing: ->
  @set 'isProcessing', false

actions:
  savePost: ->
    myModel.get('children').then (children) =>
      children.forEach (child) =>
        child.then (resolvedChild) =>
          Ember.run.debounce @, 'finishProcessing', 500

相关问答

更多
  • style属性必须与bindAttr绑定,将样式作为一个整体传递,而不仅仅是其中一个属性,因为它不理解。 此属性仅允许您以字符串形式访问样式,以直接元素为目标。 如果你这样定义它,就不可能绑定到样式的属性。 所以这是我的消化 :我已经创建了几个“模型”类,如下所示,实现了一个返回宽度的属性: var WidthEnabledModel = Em.Object.extend({ width: 100, unit: "px", widthString: function() { ...
  • 我试图重现你的问题。 似乎对我来说工作正常 - 在emberjs.jsbin.com上演示 。 你可以做更多的事情Ember.js的方式。 控制器: App.AddView = Ember.View.extend({ classNameBindings: [ 'enter:enter:leave'], enter: false, dragEnter: function(event) { this.set('enter', true); this.set('text', 'Drop ...
  • 请将您的代码包装在Ember.run.next中 。 喜欢这个: savePost: function() { this.set('isProcessing', true); Em.run.next(this, function() { //just some synchronous code that takes some time (the time inbetween the two alerts) var i=0,a; alert(' ...
  • [解决了] 我必须用Ember.run.later函数将我的peekAll在一个RSVP承诺对象中。 答案在异步路由文档中 - https://guides.emberjs.com/v2.12.0/routing/asynchronous-routing/#toc_the-router-pauses-for-promises 。 相关代码如下: if (peekData.get('content').length === 0) { return new Ember.RSVP.Promise((resol ...
  • 对于插件,您应该添加@import介绍您的app.scss如下一个(来自插件) @import 'ember-freestyle'; @import "pod-styles"; 通常在README.md中为repo描述的这些指令。 如果是您的回购 - 请查看下一个代码https://github.com/ebryn/ember-component-css/blob/ae18f897d5b40ef1b3346d8857f6a1136d1b7b4b/lib/include-all.js#L56作为示例( ht ...
  • 你错过了你桌上的标签http://emberjs.com/blog/2014/03/30/ember-1-5-0-and-ember-1-6-beta-released.html 。 You're missing your tag for your table http://emberjs.com/blog/2014/03/30/ember-1-5-0-and-ember-1-6-beta-released.html.
  • 基本上,您需要为select创建一个组数组,然后是一个计算属性,它对所选值的更改做出反应,从而对整个值集进行过滤。 这是一个工作的jsbin Basically you need to create an array of groups for the select and then, a computed property that reacts to the changes of the value selected, making a filter of the whole set of values ...
  • application.html需要由Ember.Handlebars编译。 如果您将其内容放在并放置在页面的body或body中,它将自动编译并呈现给您。 为应用程序变量App命名也是一种好习惯。 如果要渲染,则应将您的name移至App.ApplicationController 。 http://emberjs.com/guides是创建Ember应用程序的良好起点。 汤姆戴尔的新视频肯定会帮助你。 http://j ...
  • 您粘贴的CSS规则使用后代选择器,这意味着只会设置具有直接位于body元素下方的container类的元素。 但是当Ember插入Handlebars模板时,它会通过View包装它们,这会创建另一个中间DIV。 我猜这是你的风格没有出现的原因。 The CSS rule you pasted uses the descendant selector, which means only elements with the container class that are directly below the ...
  • 三个CSS3D渲染器只是浏览器自己的渲染器的一个简单抽象,因此不应该与使用Ember或jQ操纵DOM元素冲突。 一旦传递给CSS3DObject构造函数,元素的3D变换就会更新,但除此之外,它仍然照常运行。 您可以根据需要操纵其内容并设置样式。 Three's CSS3D renderer is just a thin abstraction of the browsers' own renderer and therefore should not conflict with the manipulati ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)