Dear All, Suppose I have a categorical variable a=as.factor(sample(1:3,10,replace=T)) plot(a) and hist(as.numeric(a),freq=F) would give the histogram of it. But I do not know how to add the counts or percentage information for plot.factor(). hist() can do it but as a numeric variable, the x-axis is not 3 categories in this case. Thank you for any suggestion. Best wishes, Jie
Adams, Jean
2013-Aug-26 16:43 UTC
[R] plot categorical variable with percentage infomation
Jie, I'm not exactly sure what you're after. Perhaps this will help you get started. count <- table(a) prop <- count/length(a) b <- plot(a) text(b, count, prop, pos=1) Jean On Mon, Aug 26, 2013 at 11:27 AM, Jie <jimmycloud@gmail.com> wrote:> Dear All, > > Suppose I have a categorical variable > a=as.factor(sample(1:3,10,replace=T)) > > plot(a) and hist(as.numeric(a),freq=F) would give the histogram of it. > But I do not know how to add the counts or percentage information for > plot.factor(). > hist() can do it but as a numeric variable, the x-axis is not 3 > categories in this case. > Thank you for any suggestion. > > Best wishes, > Jie > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]