Hello.
I struggled the whole afternoon with a problem. I cannot solved it or find a solution on Google, despite I think it is very simple.
Summary :
I draw the barplot of a vector of nine variables (length 9). Then, I want to draw the Confidence Interval of each bar. It works for bar #1, #2 and #3. Then for #4 and above it says :
"Error in bb[4, ] : indice hors limites"
= "Error in bb[4, ] : subscript out-of-limits"
This is the code I uses for creating this barplot. Since this is an ongoing academic project, I cannot make him a reproducible example by giving the datas. However, the code is very basic.
#Vector of values to plot
type_crt <- c(mean(data_crt$err_2,na.rm = TRUE),mean(data_crt$intu_2,na.rm = TRUE),mean(data_crt$refl_2,na.rm = TRUE),mean(data_crt$err_3,na.rm = TRUE),mean(data_crt$intu_3,na.rm = TRUE),mean(data_crt$refl_3,na.rm = TRUE),mean(data_crt$err_4,na.rm = TRUE),mean(data_crt$intu_4,na.rm = TRUE),mean(data_crt$refl_4,na.rm = TRUE))
type_crt <- round(type_crt,3)
type_crt
#Barplot
barplot(type_crt, col = c("cornflowerblue"), yaxt = "n", xaxt = "n", ylim = c(0,1.2))
axis(2, at = c(0,0.2,0.4,0.6,0.8,1),las = 1)
#X-axis Labels
mtext("Error", side=1, line=1, cex = 0.5, at=0.7)
mtext("Intuitive", side=1, line=1, cex = 0.5, at=1.9)
mtext("Reflective", side=1, line=1, cex = 0.5, at=3.1)
mtext("Error", side=1, line=1, cex = 0.5, at=4.3)
mtext("Intuitive", side=1, line=1, cex = 0.5, at=5.5)
mtext("Reflective", side=1, line=1, cex = 0.5, at=6.7)
mtext("Error", side=1, line=1, cex = 0.5, at=7.9)
mtext("Intuitive", side=1, line=1, cex = 0.5, at=9.1)
mtext("Reflective", side=1, line=1, cex = 0.5, at=10.3)
#Y-axis labels
text(0.7, type_crt[1] + 0.05, labels = type_crt[1], cex=.8)
text(1.9, type_crt[2] + 0.05, labels = type_crt[2], cex=.8)
text(3.1, type_crt[3] + 0.05, labels = type_crt[3], cex=.8)
text(4.3, type_crt[4] + 0.05, labels = type_crt[4], cex=.8)
text(5.5, type_crt[5] + 0.05, labels = type_crt[5], cex=.8)
text(6.7, type_crt[6] + 0.05, labels = type_crt[6], cex=.8)
text(7.9, type_crt[7] + 0.05, labels = type_crt[7], cex=.8)
text(9.1, type_crt[8] + 0.05, labels = type_crt[8], cex=.8)
text(10.3, type_crt[9] + 0.05, labels = type_crt[9], cex=.8)
#Confidence Intervals
#IC where it works
t.test(data_crt$err_2,conf.level=0.95)
segments(bb[1,],0.0036,bb[1,],0.238, lwd = 1)
arrows(bb[1,],0.0036,bb[1,],0.238, lwd = 1,angle = 90, code = 3, length = 0.05)
t.test(data_crt$intu_2,conf.level=0.95)
segments(bb[2,],-0.025,bb[2,],0.146, lwd = 1)
arrows(bb[2,],-0.025,bb[2,],0.146, lwd = 1,angle = 90, code = 3, length = 0.05)
t.test(data_crt$refl_2,conf.level=0.95)
segments(bb[3,],0.679,bb[3,],0.957, lwd = 1)
arrows(bb[3,],0.679,bb[3,],0.957, lwd = 1,angle = 90, code = 3, length = 0.05)
#IC where it does not work
t.test(data_crt$err_3,conf.level=0.95)
segments(bb[4,],0.072,bb[4,],0.302, lwd = 1)
arrows(bb[4,],0.072,bb[4,],0.302, lwd = 1,angle = 90, code = 3, length = 0.05)
t.test(data_crt$intu_3,conf.level=0.95)
segments(bb[5,],-0.008,bb[5,],0.133, lwd = 1)
arrows(bb[5,],-0.008,bb[5,],0.133, lwd = 1,angle = 90, code = 3, length = 0.05)
t.test(data_crt$refl_3,conf.level=0.95)
segments(bb[6,],0.622,bb[6,],0.877, lwd = 1)
arrows(bb[6,],0.622,bb[6,],0.877, lwd = 1,angle = 90, code = 3, length = 0.05)
t.test(data_crt$err_4,conf.level=0.95)
segments(bb[7,],0.004,bb[7,],0.254, lwd = 1)
arrows(bb[7,],0.004,bb[7,],0.254, lwd = 1,angle = 90, code = 3, length = 0.05)
t.test(data_crt$intu_4,conf.level=0.95)
segments(bb[8,],-0.013,bb[8,],0.207, lwd = 1)
arrows(bb[8,],-0.013,bb[8,],0.207, lwd = 1,angle = 90, code = 3, length = 0.05)
t.test(data_crt$refl_4,conf.level=0.95)
segments(bb[9,],0.618,bb[9,],0.930, lwd = 1)
arrows(bb[9,],0.618,bb[9,],0.930, lwd = 1,angle = 90, code = 3, length = 0.05)
#Axis Label
mtext("CRT type", side = 1, line = 3, at = 5.5, cex = 1.2)
mtext("Consistency (Frequency)", side = 2, line = 3, at = 0.5, cex = 1.2)
I cannot understand why this is happening. I previously perfectly made barplots of 4 columns. I think this is an overall problem, because when I try to redo these barplots of 4 columns, it fails. If someone has an intuition of what is going on, thank you !