I want to put a horizontal line on my plots that is 10% below one of
the datapoints. I'm going to do this over and over, so I want it to
be a stat_summary function rather than just calculating and plotting
the values. If it use geom_hline(yintercept=2) as a layer in my
ggplot call, everything is fine. However, when I attempt to use
geom_hline with stat_summary, it seems to expect to get values for y,
yend, etc. My understanding is that it should only need a value for
yintercept. Here is the code I would like to use:
tenBelow <- function(y) {
means <- mean(y, na.rm=TRUE)
data.frame(yintercept=means*.9)
}
tenPercLine <- function(...) {
return(stat_summary(fun.data=tenBelow, geom='hline', color='red',
linetype='dashed', ...))
}
Since I can't get this to work, I'm using segments instead with this
code:
tenBelow <- function(y) {
means <- mean(y, na.rm=TRUE)
data.frame(y=means*.9, yend=means*.9, x=0, xend=15)
}
tenPercLine <- function(...) {
return(stat_summary(fun.data=tenBelow, geom='segment', color='red',
linetype='dashed', ...))
}
This is frustrating because I have to hard code the x values (which is
inelegant), and it results in a line that does not flow off the edges
of my facets, which is undesireable. (I thought I could get around
this by using x=-Inf and x=Inf, but not so).
Elaine McVey
BD Technologies
Research Triangle Park, NC
Unfortunately geom_vline is incredibly complicated and does not work
well with other statistics. Why not just perform the summary outside
of the plot?
Hadley
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2
>
> To unsubscribe, reply using "remove me" as the subject.
>
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/