[R] Violin plot for discrete variables.

Martin Maechler maechler at stat.math.ethz.ch
Mon Mar 21 18:08:58 CET 2005


>>>>> "AndyL" == Liaw, Andy <andy_liaw at merck.com>
>>>>>     on Mon, 21 Mar 2005 08:14:20 -0500 writes:

    AndyL> I'd suggest dotcharts, such as:
    AndyL> x1 <- sample(letters[1:4], 100, replace=TRUE, prob=c(.2, .3, .4, .1))
    AndyL> x2 <- sample(letters[1:4], 100, replace=TRUE, prob=c(.1, .4, .3, .2))
    AndyL> f1 <- table(x1) / length(x1)
    AndyL> f2 <- table(x2) / length(x2)
    AndyL> lev <- factor(c(names(f1), names(f2)))
    AndyL> require(lattice)

    AndyL> dotplot(lev ~ c(f1, f2), groups=rep(1:2, c(length(f1), length(f2))),
    AndyL>         panel=panel.superpose)

yes. Maybe slightly even more useful --- and closer to the 
plot(table(.)), ...) that Witold mentioned would be the
following slight variation:

dotplot(lev ~ c(f1, f2), groups=rep(1:2, c(length(f1), length(f2))),
        panel=panel.superpose, type =c("p","h"))

Note the nice lattice feature (thanks to Deepayan Sarkar!) of
allowing type to be a union of two basic types.

Martin




More information about the R-help mailing list