为什么barplot2只在R中着色3/4条?

时间:2015-11-09 15:01:34

标签: r gplots

我正在尝试使用4种不同颜色制作数据集的barplot2(上传时间太长)。问题是,只有3/4的颜色会跳过第一个栏。我在Google上搜索过我是否写得正确无误,但它应该是正确的。我也尝试用数字写颜色而不是像

这样的名字
## Barplot
library(gplots)
CIA <- t.test(tmp3)$conf.int
CIB <- t.test(tmp5)$conf.int
CIC <- t.test(tmp10)$conf.int
CID <- t.test(tmp17)$conf.int
lower <- c(CIA[1], CIB[1], CIC[1], CID[1])
upper <- c(CIA[2], CIB[2], CIC[2], CID[2])

## install.packages( pkgs= "gplots")

barplot2(c(mean3, mean5, mean10, mean17), 
plot.ci = TRUE, ci.l = lower, ci.u = upper, 
col = c("red", "blue", "yellow", "pink"), 
main ="House 3 & 5 overlap", ylim= c(0,6), 
names = c("3","5","10","17"))

但是我得到了相同的结果,它跳过第一个栏。

我尝试了什么: 在询问问题之前我已经在Stackoverflow上看了一下,但是我没有找到解决问题的方法,而且我也尝试过谷歌。由于我的数据集太长,我只会上传相关的代码,我希望你更喜欢:)

.so

结果:

编辑:没有na的:

The WebDriver Control Flow > Protractor Adaptations

1 个答案:

答案 0 :(得分:2)

tl; dr 您的第一个栏的高度可能有NA值。

通过这个可重复的例子,我无法复制:

library(gplots)
lower <- c(1,2,3,4)
upper <- c(3,4,5,6)

barplot2(c(2,3,4,5),
         plot.ci = TRUE, ci.l = lower, ci.u = upper, 
         col = c("red", "blue", "yellow", "pink"), 
         main ="House 3 & 5 overlap", ylim= c(0,6), 
         names = c("3","5","10","17"))

enter image description here

这是gplots 2.17.0,R-devel。

然而,如果我使用NA为第一个值重新绘制情节,我会得到与您相似的结果:

barplot2(c(NA,3,4,5),
         plot.ci = TRUE, ci.l = lower, ci.u = upper, 
         col = c("red", "blue", "yellow", "pink"), 
         main ="House 3 & 5 overlap", ylim= c(0,6), 
         names = c("3","5","10","17"))

enter image description here