如何在ggroc()曲线上添加特定点?

时间:2019-05-22 11:13:14

标签: r

我正在尝试使用以下方法在ROC曲线上添加特定点:

g <- ggroc(c.roc, size = 0.8) + 
  labs(x="specificities", y = "sensitivities")

g  + ggplot(tibble(sensitivities=3.9558923, specificities=0.8552395), aes(x=sensitivities, y=specificities)) +
  geom_point(colour="blue")

但不起作用:

  

错误:不知道如何添加ggplot(tibble(灵敏度= 3.9558923,   特异性= 0.8552395),aes(x =敏感性,y =   特异性))的情节

1 个答案:

答案 0 :(得分:0)

您要做的是ggroc() + ggplot() + geom_point(),它实际上是ggplot() + ggplot() + geom_point()。与ggplot类似,ggroc期望使用geom层,而不是另一个数据层。要添加新数据,您可以将其传递到您的几何中。这应该起作用:

g <- ggroc(c.roc, size = 0.8) +
    labs(x="specificities", y = "sensitivities")

# You don't need ggplot. Just pass data into your geom.
g + geom_point(data = tibble(sensitivities=0.9558923, # Should be less than one.
                             specificities=0.8552395
                             ),
               mapping = aes(x=sensitivities, y=specificities),
               colour = "blue")

只需确保colouraes之外。另请注意,ROC x和y比例尺为0到1,这意味着sensitivities = 3.9558923将把点放在绘图区域之外。我已将其更改为高于0.9558923。