RE: [R] Violin plot for discrete variables.

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Tue 22 Mar 2005 - 04:08:58 EST

>>>>> "AndyL" == Liaw, Andy <andy_liaw@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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Mar 22 04:22:01 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:52 EST