Skip to content

Plot Data Points in boxplots

9 messages · Aric Gregson, Gabor Grothendieck, Paul Murrell +3 more

#
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:
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
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?

thanks,

aric
#
Try this:

boxplot(Sepal.Length ~ Species, iris)
with(iris, stripchart(Sepal.Length ~ Species, vertical = TRUE, add = TRUE))
On 9/27/05, Aric Gregson <aorchid at mac.com> wrote:
#
--On 9/27/05 8:55 PM -0400 Gabor Grothendieck sent:
Thanks very much for the hint. I did something very similar with decent 
results. The only problem I am having now is that I cannot figure out 
how to make stripchart plot without a box or axis. Alternatively, I can 
use DOTplot from UsingR, but I cannot find out how to rotate it for 
vertical.

thanks,

aric
#
Hi
Aric Gregson wrote:
You might also like to take a look at Figure 3.27 (and associated R 
code) on
http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter3.html

Paul

  
    
#
Is this any better?  For more along these lines, check out ?bxp for
numerous options which are accepted by boxplot, not just bxp:

boxplot(Sepal.Length ~ Species, iris,
    boxcol = 1, medcol = 2, whiskcol = 0, staplecol = 4, outcol = 0,
    boxfill = "wheat", boxlty = 0)
with(iris, stripchart(Sepal.Length ~ Species, vertical = TRUE, add = TRUE))
On 9/28/05, Aric Gregson <aorchid at mac.com> wrote:
#
vincent> Paul Murrell a ??crit :
    >> You might also like to take a look at Figure 3.27 (and
    >> associated R code) on
    >> http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter3.html

    vincent> Thank you very much for making this page available.
    vincent> The power of R graphics, and the number of options,
    vincent> makes such examples very useful.  (At least for
    vincent> beginners like me !)  Thanks.

To really thank Paul, you should buy the book to which the above
web page refers :
  http://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html

A very nice and useful book to have, indeed!

Martin Maechler, ETH Zurich
#
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
#
Martin Maechler a ??crit :
I just broked my piggy bank for Peter Dalgaard's one,
.... so I'll have to wait a bit before it blows out again.

(Peter Dalgaard
Introductory Statistics With R
http://www.amazon.fr/exec/obidos/ASIN/0387954759/qid=1127989069/sr=1-1/ref=sr_1_0_1/171-5704479-0348209
, also very useful as an introduction.)