如何使用ggplot2在直方图上添加多个vline

时间:2019-01-11 14:12:45

标签: r histogram geom-vline

我绘制了一个直方图,显示Histogram   当分配不平衡的概率之和分别为50%,80%和90%时,我想添加垂直线。

我已经构建了直方图,但是无法添加上述垂直线。

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

当分配失衡的概率之和分别为50%,80%和90%时,我期望垂直线

1 个答案:

答案 0 :(得分:0)

您可能只需要使用Read-S3Object -BucketName $bucket -Key $key/$config_name -File $config_name | Out-Null 。如果您需要它们位于.5,.8和点.9的位置,则应该是:

geom_vline()

但是您当然可以根据累积概率的计算来编码这些值。