我試圖更改特定圖形中的節點顏色,但V(gsna)$color
命令不起作用。出於某種原因,我可以改變形狀,但不是顏色。具體來說,我想改變佔用每個粘性塊的節點的顏色。黑白打印的默認顏色讀數不好。如何更改粘合塊的節點顏色?
數據集sna是一個2模式非對稱關聯矩陣。下面是一個例子(在現實中,數據集要大的多):
Attr1 Attr2 Attr3 Attr4 Attr5
Subj1 1 0 0 1 1
Subj2 1 0 0 1 1
Subj3 1 0 1 0 1
Subj4 1 0 0 1 1
Subj5 0 1 0 0 0
Subj6 0 1 1 0 0
我用cohesive.blocks()命令創建分級嵌套塊。主題由圓圈表示,屬性用正方形表示。 這裏是我的代碼:
library(igraph)
as.matrix(sna) -> sna
gsna <- graph.incidence(sna)
bloc <- cohesive.blocks(gsna)
par(mar=c(.05,.05,.05,.05),cex=.8)
V(gsna)[V(gsna)$type == 1]$shape <- "square"
V(gsna)[V(gsna)$type == 0]$shape <- "circle"
plot(bloc,gsna,layout=layout.fruchterman.reingold,vertex.size=5,edge.color="gray40",
vertex.label.color="black",mark.groups=blocks(bloc))
我也使用vcol <- colorRampPalette(c("red4","green","aliceblue"))
並添加vertex.color=vcol
選項情節()函數嘗試過,但是這並不能改變什麼。