0

I'm trying to add confidence intervals to some code I'm writing on a bar plot. The code looks like this:

Vis_Graph <- ggplot(avgtable, aes(x = reorder(Type.of.Participation, GraduatedEver), GraduatedEver, 
fill = Type.of.Participation)) +
  geom_col() +
  ggtitle("Chance of Student Graduation Rates by HIP") +
  labs(x = "Type of High Impact Practice", y = "Average Chance of Graduating (percentage)") +
  labs(colour = "Type of Participation") +
  theme(legend.position="none") +
  (MyGraphTheme)
#Print the Graph
print(Vis_Graph + MyGraphTheme)
#Reorder the graph to a horizontal layout
Vis_Graph + coord_flip()

Bear in mind I'm a pre-law college student taking a coding class for fun so I'm sure what I have isn't great but the professor challenged me to add confidence intervals for fun so I'm giving it a go.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What statistical modeling assumptions do you want to make to calculate confidence intervals? Since you are using `geom_col` i assume you have pre-calculated the y-value. You'd also have to calculate some measure of variability. – MrFlick Nov 14 '19 at 19:20
  • 2
    geom_col uses the values in the data argument, presumably calculated from some other data source, so you would also need to calculate the confidence intervals from that original data source first. This seems to be more of a statstics question: "how to calculate a confidence interval around the values I got from some other data?" Not really on-topic for a coding site. More of a lack of stats knowledge. – IRTFM Nov 14 '19 at 19:26
  • Since you're plotting actual, discrete data, the only uncertainty would seem to be in the average. So, if you can determine that, come back with the data and it will be a breeze to add error bars ```geom_errorbar()``` – markhogue Nov 14 '19 at 19:42
  • I appreciate the help so far and will go ahead and scrap the post. I'm using a data set with about 24,000 different entries from my university academics department so I don't know how I'd go about making an easily reproducible script for you guys to use. It defintely stems from a lack of stats knowledge on my part. Thanks for those of you who responded! – Alec Horner Nov 14 '19 at 19:49

0 Answers0