我想将标签添加到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()
答案 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)