关系网络图(igraph)-1

1.添加或删除节点
vertex()和vertices()
函数通过”+”增加节点,没有命名的参数作为新节点的节点名称,命名的参数作为新节点的节点属性;
函数通过”-“删除节点,要删除的节点用c()传递

g <- make_empty_graph() +
   vertices(letters[1:10]) +
    vertices("foo", "bar", "bar2", "foobar2")
plot(g)

2.添加或删除关系
edge()和edges()
edge是edges()函数的别名,当增加一个节点时用edge()函数

g <- g+edge("a","b")
g <- g + edges("foo", "bar", "bar2", "foobar2")
g <- g + edges(c("bar", "foo", "foobar2", "bar2"), 
               color="red", weight=1:2)

“bar”和”foo”有关系;”foobar2”和”bar2”有关系

3.增加路径节点
path()

g <- make_empty_graph() + vertices(letters[1:10])
g <- g + path("a", "b", "c", "d")
g <- g + path("e", "f", "g", weight=1:2, color="red")
g <- g + path(c("f", "c", "j", "d"), width=1:3, color="green")

这里的path()里面的节点关系为:依次有向关系,

4.注意以下三种用法
graph <- “foo” + make_empty_graph()
graph <- “foo” + “bar” + make_empty_graph()
graph <- “foo” + ( “bar” + make_empty_graph() )
graph <- make_empty_graph() + “foo” + “bar”
第二种会产生错误

你可能感兴趣的:(visualization,in,r)