You should provide a reproducible example so that respondents don't
have to generate their own to help you. That said, does the following
work?
library('ggplot2') # will load plyr in 0.8.9, but not 0.9.0
# library('plyr') # uncomment for 0.9.0
# fake data
DF <- data.frame(gp = rep(LETTERS[1:10], each = 20), y = rnorm(200))
# function to produce a CI and return it as a data frame, along with the mean
cifun <- function(d, level = 0.95) {
quant <- (1 + level)/2
n <- length(d$y)
m <- mean(d$y, na.rm = TRUE)
se <- sd(d$y, na.rm = TRUE)/sqrt(length(d$y))
data.frame(mean = m, lcl = m - qt(quant, n - 1),
ucl = m + qt(quant, n - 1))
}
v <- ddply(DF, .(gp), cifun)
# need to produce a data frame of intercepts if you have more than one
xints <- data.frame(x = c(-2, 2))
ggplot(v, aes(y = gp)) +
geom_point(aes(x = mean), size = 3, colour = 'red') +
geom_errorbarh(aes(x = mean, xmin = lcl, xmax = ucl),
colour = 'red', size = 1, width = 0.2) +
geom_vline(data = xints, aes(xintercept = x), colour = 'blue', size = 1)
Notes:
(1) If you want a confidence level different from 0.95, you pass the
level = argument after the name of the function; e.g., ddply(DF,
.(gp), cifun, level = 0.8)
(2) If you only need one threshold, then you can set the intercept in
geom_vline(), e.g.,
geom_vline(xintercept = 2.2, colour = 'blue', size = 1)
HTH,
Dennis
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2