Ggplot2 allows one to add error bars to a plot. To calculate the error bar limits for you, it wraps functions from Hmisc. For example, to bootstrap one can use the mean_cl_boot option:
m <- ggplot(mtcars, aes(x=cyl, y=am)) + stat_summary(fun.y=mean,geom="point")
m2 <- m + stat_summary(fun.data = "mean_cl_boot", geom = "errorbar", conf.int=.95)
m2
But what if you need to write a custom function to calculate the error bar limits? How should the function be written to be invoked from a stat_summary call?