[R] Violin plot for discrete variables.
Deepayan Sarkar
deepayan at stat.wisc.edu
Sat Apr 9 21:24:12 CEST 2005
On Monday 21 March 2005 11:08, Martin Maechler wrote:
> >>>>> "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"))
(Missed this earlier, sorry.)
Wouldn't grouped barcharts be more effective? e.g.,
barplot(rbind(f1, f2), beside = TRUE)
or
barchart(~f1 + f2, origin = 0)
In fact, one way to trick barchart into producing what I think Eryk
originally wanted would be
barchart(~f1 + (-f2), stack = TRUE)
(I don't see an obvious way of doing this with barplot.)
Deepayan
More information about the R-help
mailing list