使用R中的igraph包传播顶点属性
我正在寻找一种智能的方法,使用带有R语言的IGRAPHE包在有向图中传播顶点属性。我对网络的命名法和性质不太熟悉,但我会尽力的 例如:使用R中的igraph包传播顶点属性,r,igraph,R,Igraph,我正在寻找一种智能的方法,使用带有R语言的IGRAPHE包在有向图中传播顶点属性。我对网络的命名法和性质不太熟悉,但我会尽力的 例如: library(igraph) library(dplyr) from_to_df = data.frame(from = c("a", "b", "c", "d", "e", "f"), to = c("c", "c", "d", "e", "g", "g") ) attribut
library(igraph)
library(dplyr)
from_to_df = data.frame(from = c("a", "b", "c", "d", "e", "f"),
to = c("c", "c", "d", "e", "g", "g")
)
attributes_i_have = c(NA, NA, NA, 2, NA, NA, 1)
attributes_i_want_to_have = c(2, 2, 2, 2, 1, 1, 1)
color = c('red', 'red', 'red', 'green', 'red', 'red', 'green')
network_i_have = graph_from_data_frame(from_to_df, directed=T) %>%
set_vertex_attr("label", value = attributes_i_have) %>%
set_vertex_attr("color", value = color)
plot(network_i_have)
正如名字所说,这是一个图,我想对顶点属性进行反向传播,得到这样一个图:
network_i_want_to_have = graph_from_data_frame(from_to_df, directed=T)%>%
set_vertex_attr("label", value = attributes_i_want_to_have) %>%
set_vertex_attr("color", value = color)
plot(network_i_want_to_have)
感谢您的帮助