I'm trying to add the exact value on top of each column of an Histogram, i have been trying with the text function but it doesn't work. The problem is that the program it self decides the exact value to give to each column, and ther is not like in a bar-plot that I know exactly which values are been plotting. If anyone have any new idea on how to do this Thanks Matias -- View this message in context: http://r.789695.n4.nabble.com/Insert-values-to-histogram-tp3498140p3498140.html Sent from the R help mailing list archive at Nabble.com.
Are you really sure that you want to do that? Read the discussion starting with this post: http://tolstoy.newcastle.edu.au/R/e2/help/07/08/22858.html for reasons why you probably don't (yes, the question is about bar plots not histograms, but much of it will still apply). Near the end of the discussion there are examples of alternatives and some ways to add that may apply to your question if you still feel the need. Part of the answer depends on how you are creating your histogram in the first place, 3 different functions pop to my mind that create histograms (and I am sure there are plenty more if I looked), how to add numbers in each case would be very different, so any help we offered (beyond generalities mentioned above) could be more misleading than helpful without that information. -- 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 matibie > Sent: Thursday, May 05, 2011 5:50 AM > To: r-help at r-project.org > Subject: [R] Insert values to histogram > > I'm trying to add the exact value on top of each column of an > Histogram, i > have been trying with the text function but it doesn't work. > The problem is that the program it self decides the exact value to give > to > each column, and ther is not like in a bar-plot that I know exactly > which > values are been plotting. > If anyone have any new idea on how to do this > Thanks > Matias > > -- > View this message in context: http://r.789695.n4.nabble.com/Insert- > values-to-histogram-tp3498140p3498140.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.
Histograms plot data in bins - you don't get the exact value, because each bin contains a range of values. Do you want to plot the range of values the bin contains? Also, check ?hist to see how to set the values of the breaks between the bins.
On 05/05/2011 09:50 PM, matibie wrote:> I'm trying to add the exact value on top of each column of an Histogram, i > have been trying with the text function but it doesn't work. > The problem is that the program it self decides the exact value to give to > each column, and ther is not like in a bar-plot that I know exactly which > values are been plotting.Hi Matias, You are probably using the "hist" function in the graphics package. If so, that function returns a list containing components named "counts" (for frequency histograms) and "density" (for density histograms). So if you collect that list: histinfo<-hist(...) histinfo$counts you will see the heights of the bars. As Greg has noted, many people do not agree with adding the counts to the plot, but if you want to do it, there are your numbers. Jim
An alternative approach: library(fdth) fd <- fdt(rnorm(1e3, m=10, sd=2)) plot(fd) breaks <- with(fd, seq(breaks["start"], breaks["end"], breaks["h"])) mids <- 0.5 * (breaks[-1] + breaks[-length(breaks)]) y <- fd$table[, 2] text(x=mids, y=y, lab=y, pos=3) HTH, JCFaria -- View this message in context: http://r.789695.n4.nabble.com/Insert-values-to-histogram-tp3498140p3502237.html Sent from the R help mailing list archive at Nabble.com.