首页 > 解决方案 > 垂直中心线

问题描述

对于以下示例,我想在 x 轴的值为 1 处添加一条垂直中心线。我试过geom_estcihttp://ggepi.lukewjohnston.com/reference/geom_estci.html),但我的 R 没有找到geom_estci功能。我安装了库 ggplot2 和扫帚。我试图安装 ggepi 库。但它不适用于 R 版本 3.6.1。对于以下示例,如何在 x=1 处添加垂直中心线?

  d=data.frame(drink=c("coffee","tea","water"), mean=c(3,6,2), lower=c(2.6,5.6,1.8), 
  upper=c(3.5,6.3,2.8))
  ggplot() + 
  geom_errorbarh(data=d, mapping=aes(y=drink, x=upper, xmin=upper, xmax=lower), height=0.2, size=1, 
  color="blue") + 
  geom_point(data=d, mapping=aes(y=drink, x=mean), size=4, shape=21, fill="white")

标签: rggplot2broom

解决方案


尝试添加geom_vline(xintercept = 1).

ggplot() + 
  geom_errorbarh(data=d, mapping=aes(y=drink, x=upper, xmin=upper, xmax=lower), height=0.2, size=1, 
                 color="blue") + 
  geom_point(data=d, mapping=aes(y=drink, x=mean), size=4, shape=21, fill="white") +
  geom_vline(xintercept = 1)

推荐阅读