我正在使用一个因子在 igraph 中的不同顶点上色,但需要将其设置为黑白才能提交。我找到了这个answer,但它不起作用。以下是示例代码。
nodes <- c("A","B","C","D")
chars <- c(1,0,0,1)
nodelist <- as.data.frame(cbind(nodes, chars))
edges <- as.data.frame(rbind(c("A","B",1),c("A","C",0),c("A","D",0),c("B","C",1),c("B","D",0),c("C","D",1)))
chars <- as.factor(chars)
g <- graph.data.frame(edges, nodes, directed=FALSE)
plot(g, vertex.color = chars)
看起来不错,但需要黑白
colorset = c("0"='white',"1"='black')
plot(g, vertex.color = colorset)
白纸黑字,但它弄乱了因子水平