I have been trying to draw histogram for my manscript and found some strange things that I could not figure out why. Using the same code listed below I have successfully draw histograms for a few figures with fraction labeled on Y axis less than 1 (acturally between 0 to 0.1). But one dataset gives the Y axis label 0 to 5 as fraction. This is not true, as fraction are less than 1, although the value distribution on the figure seems to me is right. The only difference between the first few datasets and last dataset is: All values for the first few data sets > 1. The values for the last data sets between 0 and <1. Any idea why this happens. Your help is highly appreciated. Charles ==================================================postscript("Figure.eps", paper="letter", horizontal=FALSE) par(mfrow=c(3,3)) par(omi=c(2,0.2,1.8,0.2), mai=c(0.4, 0.4, 0.5, 0.1) ) my.input <- read.table("input.data", header=FALSE, sep="\t") my.input.exp <- read.table("exp.data", header=FALSE, sep="\t") hist(my.input.exp[,2], breaks=40,freq = FALSE,xlab="", border = "grey30", ylab="", main="") hist(my.input[,2], breaks=40,freq = FALSE,xlab="", ylab="", main="", border = "red",add =TRUE) mtext("Fraction", side=2, line=2, cex=0.7) box() =====================================================-- View this message in context: http://www.nabble.com/Help-needed%3A-Fraction-for-Histogram-%3E-1-----tp24150345p24150345.html Sent from the R help mailing list archive at Nabble.com.
When freq=FALSE then the y axis is not the proportion in each group (what I am assuming you mean by fraction), but rather is scaled so that the total area of the histogram is 1 (making comparing to theoretical densities easier). If all the data values are between 0 and 1, then the height of at least one bar needs to be >= 1 for the total area to equal 1. If you want the y-axis to show relative frequency (proportion, fraction, etc.), then you either need to plot the y-axis yourself or use a different function than 'hist'. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of charles78 > Sent: Monday, June 22, 2009 10:08 AM > To: r-help at r-project.org > Subject: [R] Help needed: Fraction for Histogram > 1 ??? > > > I have been trying to draw histogram for my manscript and found some > strange > things that I could not figure out why. > > Using the same code listed below I have successfully draw histograms > for a > few figures with fraction labeled on Y axis less than 1 (acturally > between 0 > to 0.1). But one dataset gives the Y axis label 0 to 5 as fraction. > This > is not true, as fraction are less than 1, although the value > distribution on > the figure seems to me is right. > > The only difference between the first few datasets and last dataset is: > > All values for the first few data sets > 1. > > The values for the last data sets between 0 and <1. > > Any idea why this happens. > > Your help is highly appreciated. > > Charles > > ==================================================> postscript("Figure.eps", paper="letter", horizontal=FALSE) > par(mfrow=c(3,3)) > par(omi=c(2,0.2,1.8,0.2), mai=c(0.4, 0.4, 0.5, 0.1) ) > > my.input <- read.table("input.data", header=FALSE, sep="\t") > my.input.exp <- read.table("exp.data", header=FALSE, sep="\t") > > hist(my.input.exp[,2], breaks=40,freq = FALSE,xlab="", border > "grey30", > ylab="", main="") > hist(my.input[,2], breaks=40,freq = FALSE,xlab="", ylab="", main="", > border > = "red",add =TRUE) > mtext("Fraction", side=2, line=2, cex=0.7) > box() > =====================================================> -- > View this message in context: http://www.nabble.com/Help-needed%3A- > Fraction-for-Histogram-%3E-1-----tp24150345p24150345.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
I change the values by multiple 100 (from fraction to percentage) and then use the same code draw the hist. Now it works fine. The y axis labeled between 0 and 0.05. Why using fraction (value between 0 and 1) it does not work? Charles charles78 wrote:> > I have been trying to draw histogram for my manscript and found some > strange things that I could not figure out why. > > Using the same code listed below I have successfully draw histograms for a > few figures with fraction labeled on Y axis less than 1 (acturally between > 0 to 0.1). But one dataset gives the Y axis label 0 to 5 as fraction. > This is not true, as fraction are less than 1, although the value > distribution on the figure seems to me is right. > > The only difference between the first few datasets and last dataset is: > > All values for the first few data sets > 1. > > The values for the last data sets between 0 and <1. > > Any idea why this happens. > > Your help is highly appreciated. > > Charles > > ==================================================> postscript("Figure.eps", paper="letter", horizontal=FALSE) > par(mfrow=c(3,3)) > par(omi=c(2,0.2,1.8,0.2), mai=c(0.4, 0.4, 0.5, 0.1) ) > > my.input <- read.table("input.data", header=FALSE, sep="\t") > my.input.exp <- read.table("exp.data", header=FALSE, sep="\t") > > hist(my.input.exp[,2], breaks=40,freq = FALSE,xlab="", border = "grey30", > ylab="", main="") > hist(my.input[,2], breaks=40,freq = FALSE,xlab="", ylab="", main="", > border = "red",add =TRUE) > mtext("Fraction", side=2, line=2, cex=0.7) > box() > =====================================================>-- View this message in context: http://www.nabble.com/Help-needed%3A-Fraction-for-Histogram-%3E-1-----tp24150345p24166484.html Sent from the R help mailing list archive at Nabble.com.