我使用igraph顏色頂點正確顏色頂點R igraph
我有兩個CSV文件的答案和拓撲圖。
答案:(這告訴玩家k和n正確回答)
Player Q1_I1
1 k 1
2 l 0
3 n 1
4 m 0
拓撲結構:(誰連接到誰的表現)
Node.1 Node.2
1 k l
2 l k
3 l m
4 m l
5 l n
6 n l
7 n k
8 k n
我想建立使用包圖IGraph並根據其正確性爲不同顏色的頂點着色。
這是我能夠做到:
# reads answers and creates a graph from topology
answers <- read.csv("answers2.csv",header=T)
data<-read.csv('edges2.csv')
data<-graph.data.frame(data1, directed=FALSE)
g<-simplify(data)
# goes through vertices and colors them in different color, depending on correctness.
# 2 means second column (First one is the players name)
V(g)$color <- ifelse(answers[V(g), 2] == 1, "blue", "red")
plot(g, layout=layout.fruchterman.reingold, vertex.color=V(g)$color)
的問題是,在我的輸出顏色是錯誤的:
這裏M和K的標記爲正確的,而應該是N和K. 我認爲問題是因爲我沒有指定該節點應該與播放器相關,並且我試圖實現這一點,但沒有成功。
有沒有什麼想法如何實現這一目標?
@SalvadorDali:參見'get.vertex.attribute','V(g)$ value'只是一個語法糖,它調用'get.vertex.attribute'。 –
當我這樣做時,我得到一個錯誤:'提供的顏色既不是數字也不是字符'。似乎無法找到soln。 – fraxture