Dear Rgurus,
To my knowledge the best way to visualize the distribution of a discrete
variable X is
plot(table(X))
The problem which I have is the following. I have to discrete variables
X and Y which distribution I would like to compare. To overlay the
distribution of Y with lines(table(Y)) gives not satisfying results.
This is the same in case of using density or histogram.
Hence, I am wondering if there is a equivalent of the vioplot function
(package vioplot) for discrete variables
which starts with a boxplot and than adds a rotated plot(table()) plot
to each side of the box plot.
Maybee I should ask it first: Does such a plot make any sense? If not
are there better solutions?
cheers
Eryk.
--
Witold Eryk Wolski
__("< School of Mathematics and Statistics _
\__/ University of Newcastle 'v'
|| Newcastle upon Tyne, NE1 7RU, ENGLAND / \
^^ mail: witek96 at users.sourceforge.net m m
Phone : 044 (0)191 222 5376
FAX : 044 (0)191 222 8020
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
> From: Witold Eryk Wolski
>
> Dear Rgurus,
>
> To my knowledge the best way to visualize the distribution of
> a discrete
> variable X is
> plot(table(X))
>
> The problem which I have is the following. I have to discrete
> variables
> X and Y which distribution I would like to compare. To overlay the
> distribution of Y with lines(table(Y)) gives not satisfying results.
> This is the same in case of using density or histogram.
>
> Hence, I am wondering if there is a equivalent of the vioplot
> function
> (package vioplot) for discrete variables
> which starts with a boxplot and than adds a rotated
> plot(table()) plot
> to each side of the box plot.
>
> Maybee I should ask it first: Does such a plot make any sense? If not
> are there better solutions?
>
> cheers
> Eryk.
>
>
> --
> Witold Eryk Wolski
> __("< School of Mathematics and Statistics _
> \__/ University of Newcastle 'v'
> || Newcastle upon Tyne, NE1 7RU, ENGLAND / \
> ^^ mail: witek96 at users.sourceforge.net m m
> Phone : 044 (0)191 222 5376
> FAX : 044 (0)191 222 8020
>
> ______________________________________________
> R-help at 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
>
>
>
Witold Eryk Wolski <W.E.Wolski <at> ncl.ac.uk> writes: : : Dear Rgurus, : : To my knowledge the best way to visualize the distribution of a discrete : variable X is : plot(table(X)) : : The problem which I have is the following. I have to discrete variables : X and Y which distribution I would like to compare. To overlay the : distribution of Y with lines(table(Y)) gives not satisfying results. : This is the same in case of using density or histogram. : : Hence, I am wondering if there is a equivalent of the vioplot function : (package vioplot) for discrete variables : which starts with a boxplot and than adds a rotated plot(table()) plot : to each side of the box plot. : : Maybee I should ask it first: Does such a plot make any sense? If not : are there better solutions? You could try a barplot or a balloonplot: tab <- table(stack(list(x1 = x1, x2 = x2))) # x1, x2 from Andy's post barplot(t(tab), beside = TRUE) library(gplots) balloonplot(tab) Although intended for comparing data to a theoretical distribution, rootogram can compare two discrete distributions: library(vcd) rootogram(tab[,1], tab[,2]) Another possibility is to fit each distribution to a parametric form using vcd::distplot as shown in the examples on its help page.