[R] Plot Data Points in boxplots
Jim Lemon
bitwrit at ozemail.com.au
Thu Sep 29 12:13:35 CEST 2005
Aric Gregson wrote:
> Hello,
>
> I would like to plot my data in a fashion similar to a boxplot, but
> plot the true data points without a box, just overlay lines of the
> summary generated by the boxplot. I have less than 10 observations
> within each group, so I think showing the actual data would be more
> effective than the box of the boxplot. I have been unable to find a way
> to do this.
>
> Here is example data:
>
>>d168teni
>
> d168dh10i d168hb10i d168icc10i d168rcs10i d168t410i d168tb410i
> 1 72 52 29 80 39 68
> 2 76 47 28 68 49 21
> 3 123 85 87 71 164 137
> 4 58 47 50 70 18 1
>
>
>>boxplot(d168teni)
>
>
> works to describe the data (each column a column in the plot). However,
> instead of the boxes, I want the data plotted (in a column) with the 5
> summary lines drawn over the points.
>
> I have tried using functions from Design and have been unable to find a
> solution. I think I am missing the point.
>
> Any suggestions on where to look or how to approach this differently?
>
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
More information about the R-help
mailing list