How do I draw an arrow on a histogram drawn using ggplot2?

Posted by jon on Stack Overflow See other posts from Stack Overflow or by jon
Published on 2012-06-20T14:39:56Z Indexed on 2012/06/29 21:16 UTC
Read the original article Hit count: 254

Filed under:
|
|

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

enter image description here

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))

© Stack Overflow or respective owner

Related posts about r

    Related posts about ggplot2