1

私のデータセットには、ID (N= 1000)、予想スコア、実際のスコアの 3 つの列が含まれています。スコアは 1、2、3、または 4 です。

シミュレーションデータはこちら

ID <- seq(from = 1, to = 1000, by=1)
actual <- round(runif(1000, min=1, max=4))
expected <- round(runif(1000, min=1, max=4))
mydata <- data.frame(ID, actual, expected)

を使用して分割表を簡単に作成できます

table(mydata$actual, mydata$expected)

IDごとにこのデータをプロットする必要があります。したがって、プロットが 1000 かける 1000 の行列になると想像してください。

If Actual=Expected, the color of these cells will be white
If Actual < Expected, the color of these cells will be red
If Actual > Expected, the color of these cells will be blue
4

1 に答える 1

1

実際と予想のペアごとに 1 つの ID しかないため、線形グラフになります。実際の値と期待値をプロットしたくありませんよね?

ID <- seq(from = 1, to = 1000, by=1)
actual <- round(runif(1000, min=1, max=4))
expected <- round(runif(1000, min=1, max=4))
mydata <- data.frame(ID, actual, expected)
View(mydata)
t = table(mydata$actual, mydata$expected)
attach(mydata)
col1 = ifelse(actual == expected , "white", ifelse(actual < expected, "red", "blue")) 
plot(ID,col=col1)

ここに画像の説明を入力

ただし、周波数を表す色とボックスを含む 4x4 マトリックスが必要な場合は、次のようにします。

plot(t,col=col1) 

ここに画像の説明を入力

編集。私は、あなたが望むのは、実際のANY対ANYのマップであると思いますか?これはよりエレガントな方法で行うことができますが、時間がないため、ご希望の色で完全なソリューションを提供することはできません. これは、基本的な色を使用した簡単なソリューションです (ただし、配色もコード化されています)。N=5 だとします。

set.seed(12345)
ID <- seq(from = 1, to = 5, by=1)
actual <- round(runif(5, min=1, max=4))
expected <- round(runif(5, min=1, max=4))
mydata <- data.frame(ID, actual, expected)

> mydata
  ID actual expected
1  1      3        1
2  2      4        2
3  3      3        3
4  4      4        3
5  5      2        4

colID = matrix("",5,5)
arr = matrix(0,5,5)
for (i in 1:5) {
  for (j in 1:5) {
    colID[i,j] = ifelse(actual[i] == expected[j] , "green", ifelse(actual[i] < expected[j], "red", "blue")) 
    arr[i,j] = ifelse(actual[i] == expected[j] , 1, ifelse(actual[i] < expected[j], 2, 3)) 
  }  
}

> arr
     [,1] [,2] [,3] [,4] [,5]
[1,]    3    3    1    1    2
[2,]    3    3    3    3    1
[3,]    3    3    1    1    2
[4,]    3    3    3    3    1
[5,]    3    1    2    2    2
> colID
     [,1]   [,2]    [,3]    [,4]    [,5]   
[1,] "blue" "blue"  "green" "green" "red"  
[2,] "blue" "blue"  "blue"  "blue"  "green"
[3,] "blue" "blue"  "green" "green" "red"  
[4,] "blue" "blue"  "blue"  "blue"  "green"
[5,] "blue" "green" "red"   "red"   "red"  

> image(arr)

ここに画像の説明を入力

ロジック - カスタム カラーまたはカスタム整数 (1、2、3) の 3 つのレベルで NxN の配列を作成し、それをイメージとしてプロットします。時間が許せば、画像の色をカスタマイズできるように努めますが、保証はできません。

于 2015-04-30T18:27:24.183 に答える