Hi all, I'm a new R user. I have the following information about a data set and how to make a histogram? data number of observations 0-2 25 2-10 10 10-100 10 100-1000 5 I tried barplot(height=...,width=...,...), the output looks right but the x-axis is missing. How to fix it? Also can I use<hist> to draw it? Thanks! WX
it's a frequency histogram. The total area of the bars is 1, and the area of each bar represents its frequency, i.e. 25/50,10/50,10/50,5/50, respectively. And the width of the bars are different. On Jan 28, 2009, at 5:50 PM, Wenxia Li wrote:> Hi all, > > I'm a new R user. I have the following information about a data set > and how to make a histogram? > data number of observations > 0-2 25 > 2-10 10 > 10-100 10 > 100-1000 5 > > I tried barplot(height=...,width=...,...), the output looks right > but the x-axis is missing. How to fix it? > Also can I use<hist> to draw it? > > Thanks! > > WX > >
Try this:> x <- read.table(textConnection("0-2 25+ 2-10 10 + 10-100 10 + 100-1000 5"))> > xV1 V2 1 0-2 25 2 2-10 10 3 10-100 10 4 100-1000 5> ?barplot > x <- read.table(textConnection("0-2 25+ 2-10 10 + 10-100 10 + 100-1000 5"))> barplot(x$V2, names.arg=x$V1) >On Wed, Jan 28, 2009 at 4:50 AM, Wenxia Li <ringingfeeling at gmail.com> wrote:> Hi all, > > I'm a new R user. I have the following information about a data set and how > to make a histogram? > data number of observations > 0-2 25 > 2-10 10 > 10-100 10 > 100-1000 5 > > I tried barplot(height=...,width=...,...), the output looks right but the > x-axis is missing. How to fix it? > Also can I use<hist> to draw it? > > Thanks! > > WX > > ______________________________________________ > R-help at 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Dear Wenxia, Take a look at this post: http://www.nabble.com/Histogram-for-grouped-data-in-R-to21624806.html#a21624806 HTH, Jorge On Wed, Jan 28, 2009 at 4:50 AM, Wenxia Li <ringingfeeling@gmail.com> wrote:> Hi all, > > I'm a new R user. I have the following information about a data set and how > to make a histogram? > data number of observations > 0-2 25 > 2-10 10 > 10-100 10 > 100-1000 5 > > I tried barplot(height=...,width=...,...), the output looks right but the > x-axis is missing. How to fix it? > Also can I use<hist> to draw it? > > Thanks! > > WX > > ______________________________________________ > 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]]