分别注释分面图的 AUC 值
Annotate AUC values for facet plots separately
有没有办法单独注释分面图的 AUC 值?下面的示例代码在两个图上注释了两个 AUC 值。这对我来说尤其成问题,因为我需要绘制 ~10 个 ROC 图,使注释非常 long/unintelligible 如下所示。谢谢。
library(plotROC)
set.seed(2529)
D.ex <- rbinom(200, size = 1, prob = .5)
M1 <- rnorm(200, mean = D.ex, sd = .65)
M2 <- rnorm(200, mean = D.ex, sd = 1.5)
M3 <- rnorm(200, mean = D.ex, sd = 1.7)
M4 <- rnorm(200, mean = D.ex, sd = 1.8)
M5 <- rnorm(200, mean = D.ex, sd = 1.9)
M6 <- rnorm(200, mean = D.ex, sd = 2.0)
M7 <- rnorm(200, mean = D.ex, sd = 2.2)
M8 <- rnorm(200, mean = D.ex, sd = 2.5)
M9 <- rnorm(200, mean = D.ex, sd = 2.7)
M10 <- rnorm(200, mean = D.ex, sd = 3.0)
test <- data.frame(D = D.ex, D.str = c("Healthy", "Ill")[D.ex + 1], M1 = M1, M2 = M2, M3 = M3, M4 = M4, M5 = M5, M6 = M6, M7 = M7, M8 = M8, M9 = M9, M10 = M10,
stringsAsFactors = FALSE)
longtest <- melt_roc(test, "D", c("M1", "M2", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "M10"))
pairplot <- ggplot(longtest, aes(d = D, m = M)) + geom_roc() + facet_wrap(~name)
pairplot + geom_rocci(linetype = 1)
pairplot +
style_roc(theme = theme_grey) +
theme(axis.text = element_text(colour = "blue")) +
ggtitle("Themes and annotations") +
facet_wrap(~name) +
annotate("text", x = .75, y = .25, label = paste("AUC =", round(calc_auc(pairplot)["AUC"], 2)))
由于通往每个方面的字符串是相同的,这意味着注释的输入向量可能只包含一个值。您可以通过 运行:
验证情况是否如此
paste("AUC =", round(calc_auc(pairplot)["AUC"], 2))
[1] "AUC = c(0.83, 0.6, 0.68, 0.63, 0.67, 0.64, 0.68, 0.63, 0.61, 0.59)"
这确实是一个值。
如果您查看进行舍入的部分,它会返回一个数据框:
round(calc_auc(pairplot)["AUC"], 2)
AUC
1 0.83
2 0.60
3 0.68
4 0.63
5 0.67
6 0.64
7 0.68
8 0.63
9 0.61
10 0.59
并将数据框的字符串表示粘贴到前缀 "AUC ="。您可以通过返回值向量而不是将整个数据帧传递给 paste
函数来解决此问题。
paste("AUC = ", round(calc_auc(pairplot)[["AUC"]], 2))
# or equally
paste("AUC = ", round(calc_auc(pairplot)$AUC, 2))
然后你就会得到你想要的结果。
有没有办法单独注释分面图的 AUC 值?下面的示例代码在两个图上注释了两个 AUC 值。这对我来说尤其成问题,因为我需要绘制 ~10 个 ROC 图,使注释非常 long/unintelligible 如下所示。谢谢。
library(plotROC)
set.seed(2529)
D.ex <- rbinom(200, size = 1, prob = .5)
M1 <- rnorm(200, mean = D.ex, sd = .65)
M2 <- rnorm(200, mean = D.ex, sd = 1.5)
M3 <- rnorm(200, mean = D.ex, sd = 1.7)
M4 <- rnorm(200, mean = D.ex, sd = 1.8)
M5 <- rnorm(200, mean = D.ex, sd = 1.9)
M6 <- rnorm(200, mean = D.ex, sd = 2.0)
M7 <- rnorm(200, mean = D.ex, sd = 2.2)
M8 <- rnorm(200, mean = D.ex, sd = 2.5)
M9 <- rnorm(200, mean = D.ex, sd = 2.7)
M10 <- rnorm(200, mean = D.ex, sd = 3.0)
test <- data.frame(D = D.ex, D.str = c("Healthy", "Ill")[D.ex + 1], M1 = M1, M2 = M2, M3 = M3, M4 = M4, M5 = M5, M6 = M6, M7 = M7, M8 = M8, M9 = M9, M10 = M10,
stringsAsFactors = FALSE)
longtest <- melt_roc(test, "D", c("M1", "M2", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "M10"))
pairplot <- ggplot(longtest, aes(d = D, m = M)) + geom_roc() + facet_wrap(~name)
pairplot + geom_rocci(linetype = 1)
pairplot +
style_roc(theme = theme_grey) +
theme(axis.text = element_text(colour = "blue")) +
ggtitle("Themes and annotations") +
facet_wrap(~name) +
annotate("text", x = .75, y = .25, label = paste("AUC =", round(calc_auc(pairplot)["AUC"], 2)))
由于通往每个方面的字符串是相同的,这意味着注释的输入向量可能只包含一个值。您可以通过 运行:
验证情况是否如此paste("AUC =", round(calc_auc(pairplot)["AUC"], 2))
[1] "AUC = c(0.83, 0.6, 0.68, 0.63, 0.67, 0.64, 0.68, 0.63, 0.61, 0.59)"
这确实是一个值。
如果您查看进行舍入的部分,它会返回一个数据框:
round(calc_auc(pairplot)["AUC"], 2)
AUC
1 0.83
2 0.60
3 0.68
4 0.63
5 0.67
6 0.64
7 0.68
8 0.63
9 0.61
10 0.59
并将数据框的字符串表示粘贴到前缀 "AUC ="。您可以通过返回值向量而不是将整个数据帧传递给 paste
函数来解决此问题。
paste("AUC = ", round(calc_auc(pairplot)[["AUC"]], 2))
# or equally
paste("AUC = ", round(calc_auc(pairplot)$AUC, 2))
然后你就会得到你想要的结果。