ggplot

2016-06-18 19 views
6

का उपयोग करते हुए आर में प्लॉट भ्रम मैट्रिक्स मेरे पास गणना के मूल्यों के साथ दो भ्रम मैट्रिक्स हैं जो वास्तविक सकारात्मक (टीपी), झूठी सकारात्मक (एफपी), वास्तविक नकारात्मक (टीएन) और झूठी नकारात्मक (एफएन) हैं, जो दो अलग-अलग तरीकों से संबंधित हैं। मैं उन्हें enter image description hereggplot

मेरा मानना ​​है कि पहलू ग्रिड या पहलू लपेटें यह कर सकती हैं, लेकिन मुझे शुरुआत करना मुश्किल लगता है। यहाँ दो भ्रम मैट्रिक्स का डेटा Method1 और Method2 को

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

उत्तर

9

इसी यह एक अच्छी शुरुआत

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

enter image description here

0

एक MYaseen208 के उत्तर पर आधारित थोड़ा अधिक मॉड्यूलर समाधान। बड़े डेटा सेट के लिए और अधिक प्रभावी हो सकता है/बहुपद वर्गीकरण:

confusion_matrix <- as.data.frame(table(predicted_class, actual_class)) 

ggplot(data = confusion_matrix 
     mapping = aes(x = predicted_class, 
        y = Var2)) + 
    geom_tile(aes(fill = Freq)) + 
    geom_text(aes(label = sprintf("%1.0f", Freq)), vjust = 1) + 
    scale_fill_gradient(low = "blue", 
         high = "red", 
         trans = "log") # if your results aren't quite as clear as the above example