[R] Vaseplots
Liaw, Andy
andy_liaw at merck.com
Mon Jul 12 21:47:34 CEST 2004
I don't have that article handy, but it sounds like `violin plots' that I've
read (also in Am. Stat.) quite a while ago. I wrote a S-PLUS function to do
something like it back in the dark ages. It probably isn't too hard to
modify for use with R. See if it does something similar:
violin.plot<-function(y, x=NULL, ...) {
if (is.null(x)) {
cx <- boxplot(y,style.bxp='old')
den.y <- ksmooth(y,ker='n')
polygon(c(cx+40*den.y$y,cx-40*rev(den.y$y)),
c(den.y$x,rev(den.y$x)),...)
} else {
if (!is.factor(x)) x<-factor(x)
cx <- boxplot(split(y,x),style.bxp='old')
lev.x<-levels(x)
wd<-45/length(lev.x)
for(i in 1:length(lev.x)) {
den.y<-ksmooth(y[x==lev.x[i]],ker='n')
polygon(c(cx[i]+wd*den.y$y,cx[i]-wd*rev(den.y$y)),
c(den.y$x,rev(den.y$x)),...)
}
}
}
[Note that I had to do quite a bit of fudging to get the x-coordinates sort
of right in S-PLUS. In R this is a LOT easier.]
Andy
> From: Peter Flom
>
> In The American Statistician vol 42 (1988) pages 257 - 280, Yoav
> Benjamini investigates some variations on the box plot, including
> vaseplots, which maek the width of each box vary proportionally to he
> estimated density at a particular point.
>
> Has anyone implemented these in R ?
>
> Thanks as always
>
> Peter
>
More information about the R-help
mailing list