Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6148757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:20:09+00:00 2026-05-23T19:20:09+00:00

Ggplot2 allows one to add error bars to a plot. To calculate the error

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:20:10+00:00Added an answer on May 23, 2026 at 7:20 pm

    Here’s an example using the add4ci function from PropCIs providing a confidence interval. You just need to have the function return a list of numbers named "y", "ymin", and "ymax":

    library(PropCIs)
    add4ciForGgplot <- function(x,conf.int) {
      numCorrect <- sum(x)
      numTrials <- length(x)
      CI <- add4ci(numCorrect,numTrials,conf.int)
      triplet <- data.frame(numCorrect/numTrials, CI$conf.int[1], CI$conf.int[2])
      names(triplet) <- c("y","ymin","ymax") #this is what ggplot is expecting
      return (triplet)
    }
    
    m <- ggplot(mtcars, aes(x=cyl, y=am)) + stat_summary(fun.y=mean,geom="point")
    mCustom <- m + stat_summary(fun.data = "add4ciForGgplot", geom = "errorbar", conf.int=.95)
    mCustom
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to add spaces between bars in ggplot2. This page offers one solution:
I am trying to produce some example graphics using ggplot2, and one of the
I have a contour plot in ggplot2 that I want to map one point
is there a way in ggplot2 to get the plot type "b"? See example:
The update method of trellis plots allows one to modify a lattice plot after
I am using ggplot2 to plot simple line charts of time series data. One
Using ggplot2 I am plotting several functions and a series of points. I cannot
library(ggplot2) my_title = This is a really long title of a plot that I
library(ggplot2) This code produces a nice looking plot: qplot(cty, hwy, data = mpg, colour
I am using ggplot2 to plot a figure that contains nine facets. Each facet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.