title: R ggplot custom percentiles
body: <p><strong>For context:</strong> I'm looking at multiple different correlation coefficients.For each correlation I created a bootstrapped distribution, and I'm using the bootstrap percentile method to create to create confidence intervals for each coefficient. As I'm looking at multiple correlations, I'm actually using a more stringent alpha level, and I'll need to repeat this analysis for different data sets with different alpha corrections in the future. All of that has gone well, but I'm struggling to create a graph to represent the custom intervals as error bars. </p>
  
  <p><strong>Question:</strong> How do I create a graph in ggplot to represent the median values of my data along with custom percentiles for my error bars. My data is in a data.frame with one variable identifying the group (Analysis) and a second variable with all of the scores in the group. There are actually 10,000 cases for each level of the "Analysis" variable for a total of 40,000 rows. I've included an index printout for brevity immediately below. </p>
  
  <pre><code> &gt;BootDistOverall[c(1:2,10000:10002,20000:20002,30000:30002),]
                               Analysis       Dist
    1      Alpha by Consequences (No Outlier) -0.4286326
    2      Alpha by Consequences (No Outlier) -0.4191646
    10000  Alpha by Consequences (No Outlier) -0.5248891
    10001 Alpha by Past-30-Day Binge Drinking -0.2972018
    10002 Alpha by Past-30-Day Binge Drinking -0.3011621
    20000 Alpha by Past-30-Day Binge Drinking -0.4145920
    20001                  Q0 by Consequences  0.3689336
    20002                  Q0 by Consequences  0.4540535
    30000                  Q0 by Consequences  0.5772917
    30001    Q0 by Past-30-Day Binge Drinking  0.6655952
    30002    Q0 by Past-30-Day Binge Drinking  0.4412748
  </code></pre>
  
  <p>I've been able to create a violin plot of the data using ggplot (see link and code below), but I'd really like to have the median values of each distribution represented as well as the percentiles as error bars. I can get median values or a boxplot to represent this data, but I need the custom percentiles. </p>
  
  <p><a href="https://i.stack.imgur.com/yEWyh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yEWyh.jpg" alt="Violin plot"></a></p>
  
  <pre><code>p0 &lt;- &lt;-ggplot(BootDistOverall, aes(Analysis,Dist))+ 
      geom_violin(scale = "area", 
      color = "#002344", 
      size = 1, 
      fill = "#FECB00")+ 
      ylim(-1,1)+
      geom_hline(yintercept = 0, 
          linetype = "dashed", 
          color = "black")+
      xlab("Analysis")+
      ylab("Bootstrapped Pearson's r")+
      coord_flip()+
      theme_bw()
  </code></pre>
  
  <p>I need help creating a similar graph but with points for the median and errorbars corresponding to my custom percentiles. I've tried multiple different methods (geom_errorbar, geom_pointrange), and I can't seem to get any of them to work. The only way I've been able to make work is adding line segments to the graph individually like I would do in base R graphics with arrows()(see below for code and link), but there has to be a better way.I'm new to ggplot so there may be a simple fix, but I'm at my wits end. </p>
  
  <p><a href="https://i.stack.imgur.com/A2DK7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A2DK7.jpg" alt="Points version"></a></p>
  
  <pre><code> #Create percentile points
    Uppers = c(
        quantile(BootDist2$Dist, .995,na.rm=T),
        quantile(BootDist4$Dist, .995,na.rm=T),
        quantile(BootDist1$Dist, .995,na.rm=T),
        quantile(BootDist3$Dist, .995,na.rm=T))
  
     Lowers = c(
        quantile(BootDist2$Dist, .005,na.rm=T),
        quantile(BootDist4$Dist, .005,na.rm=T),
        quantile(BootDist1$Dist, .005,na.rm=T),
        quantile(BootDist3$Dist, .005,na.rm=T))
  
   #Create a point graph
     ggplot(BootDistOverall, aes(x=Analysis,y=Dist))+   
        stat_summary(fun.y = mean,
             geom = "point",
             shape=22,
             size=5,
             color = "#002344",
             fill = "#FECB00")+
        theme_bw()+
        coord_flip()+
        ylim(-1,1)+
        geom_hline(yintercept = 0, 
                   linetype = "dashed", 
                   color = "black")+
        xlab("Analysis")+
        ylab("Bootstrapped Pearson's r")+
    #Add error bars with geomsemgents
        geom_segment(x=1,xend=1,y=Lowers[1],yend=Uppers[1])+
        geom_segment(x=2,xend=2,y=Lowers[2],yend=Uppers[2])+
        geom_segment(x=3,xend=3,y=Lowers[3],yend=Uppers[3])+
        geom_segment(x=4,xend=4,y=Lowers[4],yend=Uppers[4])+
        geom_segment(x=.9,xend=1.1,y=Lowers[1],yend=Lowers[1])+
        geom_segment(x=.9,xend=1.1,y=Uppers[1],yend=Uppers[1])+
        geom_segment(x=1.9,xend=2.1,y=Lowers[2],yend=Lowers[2])+
        geom_segment(x=1.9,xend=2.1,y=Uppers[2],yend=Uppers[2])+
        geom_segment(x=2.9,xend=3.1,y=Lowers[3],yend=Lowers[3])+
        geom_segment(x=2.9,xend=3.1,y=Uppers[3],yend=Uppers[3])+
        geom_segment(x=3.9,xend=4.1,y=Lowers[4],yend=Lowers[4])+
        geom_segment(x=3.9,xend=4.1,y=Uppers[4],yend=Uppers[4])
  </code></pre>