r - 如何使用ggplot2在直方图上添加多个vline
问题描述
我绘制了一个直方图,显示了直方图 当分配不平衡的概率总和为 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% 时,我期望垂直线
解决方案
您可能只需要使用geom_vline()
. 如果您在 0.5、0.8 和 0.9 处需要它们,则为:
pl +
geom_vline(xintercept = .5) +
geom_vline(xintercept = .8) +
geom_vline(xintercept = .9)
但当然,您可以根据累积概率的计算对这些值进行编码。
推荐阅读
- oracle-apex-5.1 - Oracle APEX - 将字段从集合转换为 DATE 类型
- r - 我如何在 prais winsten on r 中使用 rho
- api - BIM 360 和 Revit API
- java - 如何让 Byte Buddy 将多种类型加载到同一个包装类加载器中
- reactjs - 如何在页面上导航而不重新加载页面
- javascript - 我有两个独立的功能,一个收集表单文本,另一个切换图像的显示。我无法从其他变量中提取值
- apache-spark - 动态循环所有列名的数据集
- python - 通过在一段文本中查找关键字来过滤数据框
- php - 如何在 PHP 中从画布中删除黑色背景?
- excel - 使用 Excel VBA 宏在 Word 中查找和替换页脚文本