【问题标题】:Change colours of particular bars in a bar chart - depending on two factors更改条形图中特定条形的颜色 - 取决于两个因素
【发布时间】:2012-12-25 12:02:46
【问题描述】:

我想做与此类似的事情,但要复杂一些。

Change colours of particular bars in a bar chart

这是我的数据:

x <- c(3,-1.4,0.8,-0.3,-1.2,-2.5,1.5,-1.4)
breaks <- c(-Inf, -1, 1, Inf)
cols <- c("blue", "grey", "red")[findInterval(x, vec=breaks)]
barplot(x, col = cols, horiz=T)

这就是它的作用:

chart http://www.diabolotricks.net/Rplot-test.jpg

然后我想做的是使用该更改的 p 值将统计上不显着的条形也涂成灰色。

pval<- c(0.01,0.03,0.04,0.89,0.45,0.01,0.03,0.02)

所以第四条也是灰色的。

我尝试使用 ifelse 的各种组合都无济于事。

【问题讨论】:

    标签: r plot bar-chart


    【解决方案1】:

    只需替换cols 中的相应值即可。这可以通过[&lt;- 轻松完成,或者您可以使用replace,它是同一事物的包装器

    假设您使用的是 alpha = 0.05

    myalpha <- 0.05
    cols[pval > myalpha] <- 'grey' # could also be cols <- replace(cols, pvals > 0.05, 'grey')
    barplot(x, col = cols, horiz=T)
    

    【讨论】:

      猜你喜欢
      • 2012-10-18
      • 1970-01-01
      • 2014-04-07
      • 2018-10-28
      • 2011-08-03
      • 2012-01-19
      • 1970-01-01
      • 2013-09-25
      相关资源
      最近更新 更多