簡體   English   中英

使用矩陣調整igraph中的節點大小

[英]Adjusting the node size in igraph using a matrix

我有以下網絡圖:

set.seed(1410)
df<-data.frame(
"site.x"=c(rep("a",4),rep("b",4),rep("c",4),rep("d",4)),
"site.y"=c(rep(c("e","f","g","h"),4)),
"bond.strength"=sample(1:100,16, replace=TRUE))

library(igraph)
df<-graph.data.frame(df)
V(df)$names <- c("a","b","c","d","e","f","g","h")
layOUT<-data.frame(x=c(rep(1,4),rep(2,4)),y=c(4:1,4:1))
E(df)[ bond.strength < 101 ]$color <- "red"
E(df)[ bond.strength < 67 ]$color <- "yellow"
E(df)[ bond.strength < 34 ]$color <- "green"
V(df)$color <- "white"
l<-as.matrix(layOUT)
plot(df,layout=l,vertex.size=10,vertex.label=V(df)$names,
edge.arrow.size=0.01,vertex.label.color = "black")

在此輸入圖像描述

並希望使用如下矩陣調整節點的大小:

m<-matrix(data=c(25,0,15,0,35,0,5,0,0,10,0,5,0,19,0,44), nrow=2, ncol=8)
colnames(m)<-c("a","b","c","d","e","f","g","h")
row.names(m)<-c("site.x","site.y")

        a  b  c d  e f  g  h
site.x 25 15 35 5  0 0  0  0
site.y  0  0  0 0 10 5 19 44

我是怎么走的?

你可以用

node.size<-setNames(c(25, 15, 35, 5, 10, 5, 19, 44),c("a", "b","c", "d", "e", "f", "g", "h"))
plot(df,layout=l,vertex.label=V(df)$names,
edge.arrow.size=0.01,vertex.label.color = "black",vertex.size=node.size)

所以基本上是命名的矢量。

plot(df,layout=l,vertex.label=V(df)$names,
edge.arrow.size=0.01,vertex.label.color = "black",vertex.size=as.matrix(node.size) )

也會有用

在此輸入圖像描述

更新:

如果你需要使用m矩陣

plot(df,layout=l,vertex.label=V(df)$names,
edge.arrow.size=0.01,vertex.label.color = "black",vertex.size=m[m!=0]) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM