1

I have plotted an histogram has shown Histogram I want to add vertical lines when the sum of the probability of the allocation imbalance is 50%, 80% and 90%.

I have constructed the histogram but I am unable to add the vertical lines described above.

pl <- ggplot() + 
        geom_line(data = data.frame(power1, abs(t-c)), aes(x = abs(t-c), y = power1, color = "power"), size = 1) + 
        scale_y_continuous(labels = percent_format(), sec.axis = sec_axis(~.*.3, labels = percent_format(), name = "Probability of allocation imbalance")) + 
        geom_point(data = data.frame(power1, abs(t-c)), aes(x = abs(t-c), y = power1)) + 
        geom_histogram(data = Simple_Rand_simulation, aes(x = Imbalance_all, y = ..density..*3), color = "blue",
                 binwidth = density(Simple_Rand_simulation$Imbalance_all)$bw) + 
        labs(y = "Probability of power", x = "Allocation imbalance", colour = "Parameter") + 
        theme(legend.position = c(0.8, 0.9))

pl

I expect vertical lines when the sum of the probability of the allocation imbalance is 50%, 80% and 90%

OTStats
  • 1,820
  • 1
  • 13
  • 22
Jackline
  • 59
  • 1
  • 9
  • Please read [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Darren Tsai Jan 11 '19 at 15:08

1 Answers1

0

You probably just need to use geom_vline(). If you need them at .5, .8, and point .9, it would be:

pl + 
  geom_vline(xintercept = .5) + 
  geom_vline(xintercept = .8) + 
  geom_vline(xintercept = .9)

But of course you can code those values according to the calculation of cumulative probability.

OTStats
  • 1,820
  • 1
  • 13
  • 22
jsizzle
  • 78
  • 8