Here is dataset:
set.seed(123)
myd <- data.frame (class = rep(1:4, each = 100), yvar = rnorm(400, 50,30))
require(ggplot2)
m <- ggplot(myd, aes(x = yvar))
p <- m + geom_histogram(colour = "grey40", fill = "grey40", binwidth = 10) +
facet_wrap(~class) + theme_bw( )
p + opts(panel.margin=unit(0 ,"lines"))
I want to add labels to bars which each subject class fall into and produce something like the post-powerpoint processed graph. Is there way to do this within R ? ……
Edit: we can think of different pointer such as dot or error bar, if arrow is not impossible

Let’s say the following is subjects to be labelled:
class name yvar
2 subject4 104.0
3 subject3 8.5
3 subject1 80.0
4 subject2 40.0
4 subject1 115.0
classd <- data.frame (class = c(2,3,3,4,4),
name = c ("subject4", "subject3", "subject1", "subject2", "subject1"),
yvar = c(104.0, 8.5,80.0,40.0, 115.0))
Update
optsis deprecated; usethemeinstead.Extending bdemarest’s response a little, I think this calculates the bar heights programatically. The last two columns of
arrow_poscontain the relevant information:Freqis the height of the bar;xvalin the x position of the midpoint of the bar. But still, some of the labels overlap the bars.EDIT By default
cutbounds its intervals as (b1, b2], whereas it appeas thatggplot2bounds its intervals in geom_histogram as [b1, b2). I’ve modified the code so that both bound their intervals as [b1, b2), ie the ggplot way.