Plot confusion matrix in R using ggplot

前端 未结 5 2047
情歌与酒
情歌与酒 2020-12-29 08:38

I have two confusion matrices with calculated values as true positive (tp), false positives (fp), true negatives(tn) and false negatives (fn), corresponding to two different

5条回答
  •  -上瘾入骨i
    2020-12-29 08:56

    This could be a good start

    library(ggplot2)
    ggplot(data =  dframe, mapping = aes(x = label, y = method)) +
      geom_tile(aes(fill = value), colour = "white") +
      geom_text(aes(label = sprintf("%1.0f",value)), vjust = 1) +
      scale_fill_gradient(low = "white", high = "steelblue")
    

    Edited

    TClass <- factor(c(0, 0, 1, 1))
    PClass <- factor(c(0, 1, 0, 1))
    Y      <- c(2816, 248, 34, 235)
    df <- data.frame(TClass, PClass, Y)
    
    library(ggplot2)
    ggplot(data =  df, mapping = aes(x = TClass, y = PClass)) +
      geom_tile(aes(fill = Y), colour = "white") +
      geom_text(aes(label = sprintf("%1.0f", Y)), vjust = 1) +
      scale_fill_gradient(low = "blue", high = "red") +
      theme_bw() + theme(legend.position = "none")
    

提交回复
热议问题