2015-09-22 55 views
1

我的數據幀是這樣的:geom_tile和geom_text和facet_wrap產生不正確的混淆矩陣

method1 = c("cam","sce","cam","sce","cam","sce","cam","sce","cam","sce","cam","sce","cam","sce","cam","sce"); 
method2 = c("cam","cam","sce","sce","cam","cam","sce","sce","cam","cam","sce","sce","cam","cam","sce","sce"); 
p = c(0,0.191781,0.780822,0,0,0.082192,0.890411,0,0,0.383562,0.616438,0,0,0.054795,0.863014,0); 
participant = c("LucO","LucO","LucO","LucO","ad","ad","ad","ad","arthur","arthur","arthur","arthur","evgeny","evgeny","evgeny","evgeny"); 
mydata = data.frame(method1,method2,p,participant); 

我試圖繪製每個參與者的混淆矩陣爲:

p <- ggplot(mydata, aes(x=method1, y=method2, fill=method2)) + 
    geom_tile(aes(fill = mydata$p)) + 
    geom_text(aes(fill = mydata$p, label = round(mydata$p, 3) * 100)) + 
    facet_wrap(~participant, ncol=3, scales="free_x"); 

不過,現在爲每個participant繪製錯誤的混淆矩陣。你能幫我解決這個問題嗎?謝謝。

回答

3

只是丟失mydata$p並只加上p,它會沒事的。

函數的正確的調用是:

library(ggplot2) 
p <- ggplot(mydata, aes(x=method1, y=method2, fill=method2)) + 
    geom_tile(aes(fill = p)) + 
    geom_text(aes(fill = p, label = round(p, 3) * 100)) + 
    facet_wrap(~participant, ncol=3, scales="free_x"); 
p 

輸出:

enter image description here

數據(針對圖形比較)

> mydata 
    method1 method2  p participant 
1  cam  cam 0.000000  LucO 
2  sce  cam 0.191781  LucO 
3  cam  sce 0.780822  LucO 
4  sce  sce 0.000000  LucO 
5  cam  cam 0.000000   ad 
6  sce  cam 0.082192   ad 
7  cam  sce 0.890411   ad 
8  sce  sce 0.000000   ad 
9  cam  cam 0.000000  arthur 
10  sce  cam 0.383562  arthur 
11  cam  sce 0.616438  arthur 
12  sce  sce 0.000000  arthur 
13  cam  cam 0.000000  evgeny 
14  sce  cam 0.054795  evgeny 
15  cam  sce 0.863014  evgeny 
16  sce  sce 0.000000  evgeny