2 links 而不是 igraph 中的 2-way link
2 links instead of 2-way link in igraph
我需要绘制一个具有定向连接的网络并将其保存为 SVG。我从这里举个例子:https://www.r-graph-gallery.com/251-network-with-node-size-based-on-edges-number.html
这是我的数据示例:
library(igraph)
# create data:
links=data.frame(
source=c("A","A", "A", "A", "A","J", "B", "B", "C", "C", "D","I"),
target=c("B","B", "C", "D", "J","A","E", "F", "G", "H", "I","I")
)
# Turn it into igraph object
network <- graph_from_data_frame(d=links, directed=T)
# Count the number of degree for each node:
deg <- degree(network, mode="all")
# Plot
svg("c:\temp\network01.svg",
width = 7, height = 7, pointsize = 12)
plot(network, vertex.size=30, vertex.color=rgb(0.1,0.7,0.8,0.5) , edge.arrow.size = 0.7)
dev.off()
结果图片:
除了这部分没关系:
我在这里的预期 - 更大的 link 行长度,2 links 而不是 1 2-way link。像这样:
这可能吗?
顺便说一句。图片每次生成都不一样。有时 A <-> J link 看起来更糟:
默认排版不好的时候可以手动指定排版。例如:
layout = matrix(c(0,0, 0,1, 0,-1, -1,0, 1,0, 2,0, -0.5,-2,
0.5,-2, -2,-0.5, -2,0.5), byrow = T, ncol = 2)
plot(network, vertex.size=30, vertex.color=rgb(0.1,0.7,0.8,0.5),
edge.arrow.size = 0.2, layout=layout)
请注意,指定坐标的顺序必须符合 igraph 对象中节点的顺序(您可以使用 lapply(network, names)
查看)。
另外,还有大量的自动布局功能,您可以尝试找到自己喜欢的布局。 ?layout_with_fr
提供可用布局函数的列表。例如:
plot(network, vertex.size=30, vertex.color=rgb(0.1,0.7,0.8,0.5),
edge.arrow.size = 0.2,
layout=layout_with_sugiyama(network)$layout)
我需要绘制一个具有定向连接的网络并将其保存为 SVG。我从这里举个例子:https://www.r-graph-gallery.com/251-network-with-node-size-based-on-edges-number.html
这是我的数据示例:
library(igraph)
# create data:
links=data.frame(
source=c("A","A", "A", "A", "A","J", "B", "B", "C", "C", "D","I"),
target=c("B","B", "C", "D", "J","A","E", "F", "G", "H", "I","I")
)
# Turn it into igraph object
network <- graph_from_data_frame(d=links, directed=T)
# Count the number of degree for each node:
deg <- degree(network, mode="all")
# Plot
svg("c:\temp\network01.svg",
width = 7, height = 7, pointsize = 12)
plot(network, vertex.size=30, vertex.color=rgb(0.1,0.7,0.8,0.5) , edge.arrow.size = 0.7)
dev.off()
结果图片:
除了这部分没关系:
我在这里的预期 - 更大的 link 行长度,2 links 而不是 1 2-way link。像这样:
这可能吗?
顺便说一句。图片每次生成都不一样。有时 A <-> J link 看起来更糟:
默认排版不好的时候可以手动指定排版。例如:
layout = matrix(c(0,0, 0,1, 0,-1, -1,0, 1,0, 2,0, -0.5,-2,
0.5,-2, -2,-0.5, -2,0.5), byrow = T, ncol = 2)
plot(network, vertex.size=30, vertex.color=rgb(0.1,0.7,0.8,0.5),
edge.arrow.size = 0.2, layout=layout)
请注意,指定坐标的顺序必须符合 igraph 对象中节点的顺序(您可以使用 lapply(network, names)
查看)。
另外,还有大量的自动布局功能,您可以尝试找到自己喜欢的布局。 ?layout_with_fr
提供可用布局函数的列表。例如:
plot(network, vertex.size=30, vertex.color=rgb(0.1,0.7,0.8,0.5),
edge.arrow.size = 0.2,
layout=layout_with_sugiyama(network)$layout)