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

tch*_*rty 3 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() 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Hac*_*k-R 5

你可以这样做:

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)
Run Code Online (Sandbox Code Playgroud)