如果下面这幅图是你所想要达到的效果的话,请继续往下看。如果不是,请忽略我的代码
我用了苯办法,把x轴的tick设为空,然后用annotate()人工加上组
- iris %>%
- tbl_df() %>%
- group_by(Species) %>%
- gather(type, length, 1:4) %>%
- summarise(mean = mean(length),
- conf_low = t.test(length)$conf.int[1],
- conf_high = t.test(length)$conf.int[2]) %>%
- ggplot(aes(x = Species)) +
- geom_bar(aes(y = mean), stat = "identity") +
- geom_segment(aes(xend = Species, y = conf_low, yend = conf_high),
- arrow = arrow(angle = 90, ends = "both")) +
- theme(axis.text.x = element_blank(),
- axis.line = element_line(color = "black", size = 1)) +
- annotate("text", label = c("Setosa","Versicolor","Virginica"), y = -0.2, x = 1:3)
复制代码