CMCai0104 你自己试着修改下
# Horizontal annotations with ggrepel and ggplot2
# 添加注释
library(tidyverse)
library(ggrepel)
set.seed(1234)
data <- tibble(x = seq_len(100),
y = cumsum(rnorm(100)))
anno_data <- data %>%
filter(x %% 25 == 10) %>%
mutate(text = "text")
data %>%
ggplot(aes(x, y)) +
geom_line() +
geom_label_repel(aes(label = text),
data = anno_data,
direction = "y",
nudge_y = c(-5, 5, 5, 5))
# 出自 https://gist.github.com/EmilHvitfeldt/acb849a6135a21426c260850cf0f461b