我正在构建经验 ROC 曲线,并且遇到了一些看起来不太合理的曲线。我正在使用geom_text_repel
,但它们只是为了彼此靠近。我想知道是否有人可以提供一些明智的解决方案。
数据:
structure(list(sens = c(0, 0.2, 0.2, 0.4, 0.4, 0.4, 0.4, 0.4,
0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.5, 0.5, 0.5, 0.7, 0.7, 1), one_min_spec = c(0,
0, 0, 0.021, 0.021, 0.021, 0.041, 0.041, 0.041, 0.041, 0.041,
0.041, 0.041, 0.041, 0.062, 0.062, 0.108, 0.17, 0.183, 1), cut_point = c(NA,
18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L,
5L, 4L, 3L, 2L, 1L, NA)), row.names = c(1L, 12156L, 11470L, 10784L,
10098L, 9412L, 8726L, 8040L, 7354L, 6668L, 5982L, 5296L, 4610L,
3924L, 3238L, 2552L, 1866L, 1180L, 494L, 20L), class = "data.frame")
和绘图代码:
ggplot(df, aes(one_min_spec, sens, label = cut_point)) +
geom_abline(
intercept = 0,
slope = 1,
color = "black",
linetype = "dashed"
) +
geom_path(colour = "gray") +
geom_point(colour = "black") +
geom_text_repel(size = 4) +
scale_y_continuous(limits = c(0, 1),
expand = c(0, 0)) +
scale_x_continuous(limits = c(0, 1),
expand = c(0, 0)) +
theme(text = element_text(size = 14))
我在想也许可以尝试为每个点创建一个标签,而不是如果它们在 ROC 空间中共享同一个点,则使用多个标签。即在这种情况下,它将是单个标签 6-13,而不是所有切割点都有一个。不太确定该怎么做,是否有意义?