- 已编辑
yuanfan 这个事看起来还挺复杂的,理想态是类似 ggplot2 的标签图层,或者 ggrepel 那样,可以另起一个数据,添加文本注释图层。
set.seed(2020)
library(ggplot2)
library(ggrepel)
dat <- data.frame(
x = seq(100),
y = cumsum(rnorm(100))
)
anno_data <- dat |>
subset(x %% 25 == 10) |>
transform(text = "text")
ggplot(data = dat, aes(x, y)) +
geom_line() +
geom_label_repel(aes(label = text), # 有另一份数据,新加一个图层
data = anno_data,
direction = "y",
nudge_y = c(-5, 5, 5, 5)
) +
theme_minimal()
P.S. 汤加火山位置我应该给 c(-21.0744, 183.7499)
毕竟西经 176 就是东经 184, 这样就和 quakes 数据集保持一样了。