RE: [R] Vaseplots

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Tue 13 Jul 2004 - 05:47:34 EST


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
>



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 13 05:56:47 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:52 EST