R:将geom_vline标签添加到geom_histogram标签

时间:2016-08-07 16:05:05

标签: r ggplot2

我想将标签添加到x轴,以获取geom_vline图层中的数据,而无需重新生成现有的数据:

library(dplyr)
library(ggplot2)

data_frame(x = rnorm(10000)) %>% 
  ggplot(aes(x = x)) + 
  geom_histogram(bins = 100) + 
  geom_vline(aes(xintercept = mean(x) + 2.6)) + 
  theme_bw() 

enter image description here

1 个答案:

答案 0 :(得分:2)

你可以这样做:

library(dplyr)
library(ggplot2)

data_frame(x = rnorm(10000)) %>% 
  ggplot(aes(x = x)) + 
  geom_histogram(bins = 100) + 
  geom_vline(aes(xintercept = mean(x) + 2.6)) + 
  theme_bw() +
  geom_text(aes(x=mean(x) + 2.6, label="My label text", y=0), colour="blue", angle=90)
相关问题