Skip to content
Prev 78049 / 398502 Next

Plot Data Points in boxplots

Aric Gregson wrote:
I haven't seen anything like this posted, so I'll take a punt.

noboxplot<-function(x,plot=FALSE,...) {
  boxplot.info<-boxplot(x,plot,...)
  dimx<-dim(x)
  if(is.null(dimx)) plot(1,x)
  else {
   xpts<-1:dimx[2]
   # you may want to use text() here if you want the
   # actual values displayed
   matplot(t(as.matrix(x)),axes=FALSE,xlim=c(0.5,dimx[2]+0.5),
    ylab=deparse(substitute(x)))
  }
  box()
  axis(2)
  nbp.labels<-names(x)
  if(is.null(nbp.labels)) nbp.labels<-as.character(xpts)
  axis(1,at=xpts,labels=nbp.labels)
  for(xpos in 1:dimx[2]) {
   segments(xpos-0.2,boxplot.info$stats[,xpos],
            xpos+0.2,boxplot.info$stats[,xpos],
	   lwd=c(1,1,3,1,1))
  }
  return(boxplot.info)
}

Hope it's what you want.

Jim