如何用点对应的行号索引替换箱形图上的点?

How do you replace the points on a box plot with the point's corresponding row number index?

我有一个如下所示的数据框:

Train_Table_Time_Power <- data.frame(
Skew = runif(250),
Crest = runif(250),
Kurt = runif(250),
Impulse = runif(250),
  TI = sample(c("0.05", "0.10", "0.15", "0.20"), 10, replace = TRUE)
)

然后我使用以下代码创建了一个带有点的框:

Crest_BoxPlot <- ggplot(Train_Table_Time_Power, aes(x = TI, y = Crest, color = TI)) + 
  geom_boxplot(notch = T, id=TRUE) +
  stat_summary(fun = mean, geom="point", shape=19, color="red", size=2) +
  geom_jitter(shape=16, position = position_jitter(0.2), size = 0.3) +
  labs(title = "Crest_Time", x = "TI", y = "Normalized Magnitude") +
  theme_minimal() + theme_Publication()

我想以某种方式将箱线图的各个点替换为它们的行号索引,但是,我似乎想不出办法。如果确实可行,有人可以指导我如何执行此操作吗?

只需使用 geom_text() 而不是 geom_jitter(),但请注意,由于标签重叠,可读性有限。

# add the row number as column
library(tibble)
Train_Table_Time_Power <-  rowid_to_column(Train_Table_Time_Power)

ggplot(Train_Table_Time_Power, aes(x = TI, y = Crest, color = TI, label = rowid)) + 
  geom_boxplot(notch = T, id=TRUE) +
  stat_summary(fun = mean, geom="point", shape=19, color="red", size=2) +
  geom_text(position = position_jitter(0.2)) +
  labs(title = "Crest_Time", x = "TI", y = "Normalized Magnitude") +
  theme_minimal()