Search code examples
rconfidence-interval

Confidence intervals on plot in r (using PlotCI)


I am using code as below to make a plot with confidence intervals. The problem is, that if ui is lower than y (or li is upper than y) on the plot we see line from li to y (from ui to y) not the interval (li,ui). So it is hard to say if interval contains y or not. All integrals have the same length but looking on plot I wouldn't say that. How can I change it?

number = 20
plotCI(x = 1:number, y = rep(0, number), ui = df3$`prawy koniec`, li = df3$`lewy koniec`, xlab = paste(number,'  przedziałów ufności'), ylab = '',main = '(iii)', ylim = c(-30, 30))

enter image description here


Solution

  • I decided to use plot with segments instead of PlotCI

    plot(c(-30,30),c(1,number), type="n", xlab=expression(mu), ylab=paste(number," przedziałów ufności"), yaxt="n",main="(iii)")
    segments(df1$`lewy koniec`,1:number,df1$`prawy koniec`,1:number, col="blue", lwd=1)
    abline(v=0,col="red",lwd=1)