0

I'm trying to make a barplot2 of a dataset (which is too long to upload) with 4 different colors. The problem is, only 3/4 are colored it skips the first bar. I've searched on Google to check whether I've written it correct or not, but it should be correct. I've also tried to write the colors in numbers instead of names like

col = 3:4:5:6

But I got the same result, it skips the first bar.

What I've tried: I've looked here on Stackoverflow before asking the question, but I didn't find a solution for my problem, moreover I've also tried Google. As my dataset is too long, I'm only gonna upload the relevant code, which I expect that you prefer :)

## 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"))

Result:

EDIT: Without na's:

enter image description here

Jaap
  • 81,064
  • 34
  • 182
  • 193
Mr.T
  • 27
  • 7
  • barplots are for counts not continuous data, use a boxplot or something else – rawr Nov 09 '15 at 16:04
  • I am using it to see which houses overlap. As I can see it's house 3,5,17. Can we agree on that? – Mr.T Nov 09 '15 at 16:08

1 Answers1

2

tl;dr you probably have an NA value for the height of your first bar.

With this reproducible example, I can't replicate:

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

This is with gplots 2.17.0, R-devel.

However, if I re-do the plot with an NA for the first value, I get very similar results to yours:

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

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Is there a smart way to upload the dataset? – Mr.T Nov 09 '15 at 15:09
  • 1
    well, I think the question has now reduced to "why is my value of `mean3` coming out as `NA`?" -- which is a different question. Have you read http://tinyurl.com/reproducible-000 ? – Ben Bolker Nov 09 '15 at 15:12
  • Thanks! The problem was that I forgot to remove the NA's by writing `na.rm=TRUE` in mean3 – Mr.T Nov 09 '15 at 15:14
  • Yes, and to honest, I have tried to follow it, the dput(X) shows tooo many numbers, that's why I didn't upload it. – Mr.T Nov 09 '15 at 15:15
  • So, can we agree on that bar 3 and bar 5 overlap, and bar 5 and bar 17 also overlap? Or am I wrong? – Mr.T Nov 09 '15 at 15:19
  • I've edited the question. I've uploaded the barplot without the `NA's` for `mean3` – Mr.T Nov 09 '15 at 15:30