我想将标签添加到图层数据的 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)
你可以这样做:
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)