[R] bar plot with non-zero starting level

Jim Lemon jim at bitwrit.com.au
Sun May 19 13:17:43 CEST 2013


On 05/19/2013 09:19 AM, Xianwen Chen wrote:
> Hi,
>
> I want to plot grouped bars to compare 95% confidence interval estimates
> from two models. Each bar represents a 95% confidence interval estimate
> of a coefficient from one of the two models. Each group represents
> confidence interval estimates of the same coefficient from the two models.
>
> I think such a bar plot will nicely present whether 95% confidence
> interval estimates of the same coefficient from the two models overlap.
> All these confidence intervals do not start from the x axis.
>
> I searched bar plot examples on Google. I found methods to plot bars in
> groups by barplot(). I could only specify one offset for all confidence
> interval estimates of the same model. I could not individually specify
> an offset for each confidence interval estimate. Can someone please help
> me on how I may proceed with individual offset for each of the bar in
> the plot?
>
Hi Xianwen,
It seems that you want to line up either one or both of the estimates 
for each coefficient and then display the confidence intervals as bars 
around the estimates. If so, your ordinate (y-axis) won't be very 
interpretable unless you add one for each pair of coefficients. What I 
would initially suggest is that you display the coefficient values along 
a horizontal line and use "error bars" to show the confidence intervals. 
Here is an example:

coef<-c(3.6,3.2,5.7,6.0,1.2,1.3)
CIs<-c(1.2,1.4,2.7,2.6,3.1,2.9)
plot(0,xlim=c(0.5,3.5),ylim=range(c(-CIs,CIs)),type="n",
  xlab="Coefficients",ylab="95% confidence intervals",xaxt="n")
axis(1,at=c(0.8,1.2,1.8,2.2,2.8,3.2),
  labels=c("A1","A2","B1","B2","C1","C2"))
abline(h=0)
library(plotrix)
dispersion(c(0.8,1.2,1.8,2.2,2.8,3.2),rep(0,6),ulim=CIs,interval=TRUE)
boxed.labels(c(0.8,1.2,1.8,2.2,2.8,3.2),0,coef)

Jim



More information about the R-help mailing list