我有两个混淆矩阵,其计算值分别为真阳性(tp),假阳性(fp),真阴性(tn)和假阴性(fn),分别对应于两种不同的方法。我想代表他们
r - 使用ggplot绘制R中的混淆矩阵-LMLPHP

我相信多面网格或多面包装可以做到这一点,但是我发现很难开始。
这是与方法1和方法2对应的两个混淆矩阵的数据

dframe<-structure(list(label = structure(c(4L, 2L, 1L, 3L, 4L, 2L, 1L,
3L), .Label = c("fn", "fp", "tn", "tp"), class = "factor"), value = c(9,
0, 3, 1716, 6, 3, 6, 1713), method = structure(c(1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L), .Label = c("method1", "method2"), class = "factor")), .Names = c("label",
"value", "method"), row.names = c(NA, -8L), class = "data.frame")

最佳答案

这可能是一个好的开始

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")


已编辑

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")


r - 使用ggplot绘制R中的混淆矩阵-LMLPHP

关于r - 使用ggplot绘制R中的混淆矩阵,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37897252/

10-12 17:07