R 标记geom_台阶系列(组),但不是所有点

R 标记geom_台阶系列(组),但不是所有点,r,ggplot2,ggrepel,R,Ggplot2,Ggrepel,如何在不标记每个点的情况下标记每个geom\u步骤系列(group)?以下是要标记的绘图: 以下是我通过ggrepel得到的信息: ex随机挑选三个日期怎么样 set.seed(1) n <- length(unique(ex$label)) idx <- sample(1:(nrow(ex) / n), n) + 0:(n - 1) * (nrow(ex) / n) ggplot(ex, aes(x = date, y = value, group=label)) + ge

如何在不标记每个点的情况下标记每个
geom\u步骤
系列(
group
)?以下是要标记的绘图:

以下是我通过
ggrepel
得到的信息:


ex随机挑选三个日期怎么样

set.seed(1)
n <- length(unique(ex$label))
idx <- sample(1:(nrow(ex) / n), n) + 0:(n - 1) * (nrow(ex) / n)
ggplot(ex, aes(x = date, y = value, group=label)) +
  geom_step(aes(color=label)) +
  theme_bw() +
  theme(legend.position = "none") +
  scale_x_date(breaks = "1 month", date_labels="%m-%y") +
  geom_label(data = ex[idx, ], aes(label = label))
set.seed(1)

谢谢,朱利叶斯。这肯定回答了问题。在我的情况下,我试图避免硬编码。我可以抓取最小或最大日期,但这在本例中并不理想。@EricGreen,有意义。请参阅更新。这里我假设每个系列都有相同数量的元素。
set.seed(1)
n <- length(unique(ex$label))
idx <- sample(1:(nrow(ex) / n), n) + 0:(n - 1) * (nrow(ex) / n)
ggplot(ex, aes(x = date, y = value, group=label)) +
  geom_step(aes(color=label)) +
  theme_bw() +
  theme(legend.position = "none") +
  scale_x_date(breaks = "1 month", date_labels="%m-%y") +
  geom_label(data = ex[idx, ], aes(label = label))