Hi Jean, I would like to give a histogram for a categorical variable, with x-axis be different levels, and a number of percentage showed on top of each bar. Thanks.
Best wishes, Jie On Mon, Aug 26, 2013 at 12:43 PM, Adams, Jean <jvad...@usgs.gov> wrote: > 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 <jimmycl...@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. > > ______________________________________________ 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.