hist(rbinom(1000,10,0.5),col=2,xlim=c(0,10),ylim=c(0,300)) gives a histogram with "touching bars" hist(rbinom(100000,10,0.5),col=2,xlim=c(0,10),ylim=c(0,30000)) gives a histogram with space between the bars. is there a way to control the space betweent he bars easily? -- Erich Neuwirth, Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-38624 Fax: +43-1-4277-9386 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
The basic problem is that hist() is really designed for continuous data, and you're using it with discrete data. You can either say r <- rbinom(100000,10,0.5) hist(r,10,0.5),col=2,xlim=c(0,10),ylim=c(0,30000), breaks=seq(-0.5,10.5,by=0.1)) so that the bins span (-0.5 to 0.5, 0.5 to 1.5, ...) or (arguably better, because it is more sensible with discrete data) barplot(table(r),space=0) ## note that if you're building tables of sparser data where all ## levels may not be represented you may want something like barplot(table(factor(r,levels=0:10)),space=0) # instead On Mon, 12 Nov 2001, Erich Neuwirth wrote:> hist(rbinom(1000,10,0.5),col=2,xlim=c(0,10),ylim=c(0,300)) > gives a histogram with "touching bars" > > hist(rbinom(100000,10,0.5),col=2,xlim=c(0,10),ylim=c(0,30000)) > gives a histogram with space between the bars. > > is there a way to control the space betweent he bars easily? > > > > -- > Erich Neuwirth, Computer Supported Didactics Working Group > Visit our SunSITE at http://sunsite.univie.ac.at > Phone: +43-1-4277-38624 Fax: +43-1-4277-9386 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- 318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I have a modified version of the plot.histogram that also takes the two arguments width and offset. This might be what you are looking for. See the Rd-page at: http://www.maths.lth.se/matstat/bioinformatics/software/R/library/R.base/html/plot.histogram.html The function can be downloaded at http://www.maths.lth.se/matstat/staff/hb/mypackages/R/plot.histogram.R I haven't used it in a while, but I wrote it to be able to place two or more histograms in the same plot. Cheers Henrik Bengtsson Dept. of Mathematical Statistics @ Centre for Mathematical Sciences Lund Institute of Technology/Lund University, Sweden (+2h UTC) Office: P316, +46 46 222 9611 (phone), +46 46 222 4623 (fax) h b @ m a t h s . l t h . s e On Mon, 12 Nov 2001, Erich Neuwirth wrote:> hist(rbinom(1000,10,0.5),col=2,xlim=c(0,10),ylim=c(0,300)) > gives a histogram with "touching bars" > > hist(rbinom(100000,10,0.5),col=2,xlim=c(0,10),ylim=c(0,30000)) > gives a histogram with space between the bars. > > is there a way to control the space betweent he bars easily? > > > > -- > Erich Neuwirth, Computer Supported Didactics Working Group > Visit our SunSITE at http://sunsite.univie.ac.at > Phone: +43-1-4277-38624 Fax: +43-1-4277-9386 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 12 Nov 2001, Erich Neuwirth wrote:> hist(rbinom(1000,10,0.5),col=2,xlim=c(0,10),ylim=c(0,300)) > gives a histogram with "touching bars" > > hist(rbinom(100000,10,0.5),col=2,xlim=c(0,10),ylim=c(0,30000)) > gives a histogram with space between the bars. > > is there a way to control the space betweent he bars easily?If you want to control space between the bars you probably want a barplot(), which does have this sort of control -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._