Skip to content

Violin plot for discrete variables.

2 messages · Liaw, Andy, Martin Maechler

#
I'd suggest dotcharts, such as:

x1 <- sample(letters[1:4], 100, replace=TRUE, prob=c(.2, .3, .4, .1))
x2 <- sample(letters[1:4], 100, replace=TRUE, prob=c(.1, .4, .3, .2))
f1 <- table(x1) / length(x1)
f2 <- table(x2) / length(x2)
lev <- factor(c(names(f1), names(f2)))
require(lattice)
dotplot(lev ~ c(f1, f2), groups=rep(1:2, c(length(f1), length(f2))),
        panel=panel.superpose)

HTH,
Andy
#
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