0

I am trying to create a barplot using ggplot2 in shiny that has lines representing the mean for each of the bars. In other words, there will be 5 different mean lines (that are based on the data within the 5 separate bars of the plot). Is it possible to do this?

I already know that it is possible to create an intercept that can represent the mean; however, I am unaware of being able to do this for each individual bar rather than the entire bar plot:

 geom_hline(yintercept=Mean1, size = .8,linetype="dotdash")
aosmith
  • 34,856
  • 9
  • 84
  • 118
Monty-PYTHON
  • 13
  • 1
  • 7
  • Please share some sample data. It seems irrelevant that you want the plot to appear in shiny, so don't worry about that. Just a small, copy/pasteable data frame (sharing with `dput()` is great for copy/pasteability! Or share code to simulate), and a clear description of the graph: what column on the x-axis, the y-axis, what column do you want to take a mean of...? – Gregor Thomas Jun 27 '19 at 20:18
  • I'm not entirely sure what you're after, but I know there are some tricks that can be done using geoms like `geom_errorbar()` with `ymin` and `ymax` set to the same value. This would create a horizontal line, with a width that can be controlled by `width`. There are other examples out there, but [this is the one](https://stackoverflow.com/a/35156892/2461552) I can find at the moment. – aosmith Jun 27 '19 at 22:48

0 Answers0