我正在使用 R 来绘制网络图。交互矩阵看起来
>mat
9 401 562 68 71 569 700
9 0 1 0 0 0 0 1
401 0 0 1 0 0 na 1
562 0 1 0 1 1 0 1
68 1 1 0 0 0 0 1
71 1 na 0 0 na 0 1
569 1 1 0 1 0 0 0
700 0 0 0 0 0 0 0
>DT_mat<-mat%>%
as.data.table(keep.rownames=TRUE) %>%
melt(id.vars = "rn", value.name="interaction")
>setnames(DT_mat, c("rn", "variable"), c("source", "target"))
相同交互矩阵的 Id 的元数据
>meta
compart group family genus color.group color.compart
9 Ex Prt A Ps #EF5656 #2BB065
401 Ex Prt A Ps #EF5656 #2BB065
562 Ex Fir B Rh #F7A415 #2BB065
68 In Fir C En #F7A415 #EECF17
71 In Act D Stp #47B3DA #EECF17
569 In Act D Stp #47B3DA #EECF17
700 Ex Act E Aqua #47B3DA #2BB065
>DT_meta <- as.data.table(meta, keep.rownames=TRUE)
>setkey(DT_meta, rn)
>DT_mat[, paste0(names(DT_meta), ".rows") := DT_meta[.(rn.rows)]]
1-是否可以使用 qgraph() 定义颜色?
> ig_mat <- graph.data.frame(DT_mat, directed=T)
> V(mat)$color <- ifelse(V(mat)$compart=="Ex","#EF5656","#47B3DA")
2-当有两种以上的颜色和重复使用 efelse 时,是否可以使用 igraph.plot 定义颜色?