此代码根据参与者和关系的数据框绘制图表。
library(igraph)
actors <- data.frame(name=c("Alice", "Bob", "Cecil", "David",
"Esmeralda"))
relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
"David", "Esmeralda"),
to=c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
friendship=c(4,15,5,2,11,1))
g <- graph_from_data_frame(relations, directed=TRUE, vertices=actors)
plot(g)
结果是:
我想根据 relations$friendship
的值更改弧的粗细(而不是长度)。
最佳答案
试试
plot(g,edge.width = E(g)$friendship, edge.arrow.size = E(g)$friendship)
请注意,E(g)$friendship
的第一个值被分配给 edge.arrow.size
,而不是向量。也许改进的功能会添加到 future 的 igraph
版本中。
arrow.size The size of the arrows. Currently this is a constant, so it is the same for every edge. If a vector is submitted then only the first element is used, ie. if this is taken from an edge attribute then only the attribute of the first edge is used for all arrows. This will likely change in the future.
The default value is 1.
arrow.width The width of the arrows. Currently this is a constant, so it is the same for every edge. If a vector is submitted then only the first element is used, ie. if this is taken from an edge attribute then only the attribute of the first edge is used for all arrows. This will likely change in the future.
This argument is currently only used by plot.igraph.
The default value is 1, which gives the same width as before this option appeared in igraph.
关于r - 根据包含参与者之间关系的数据框列更改边缘厚度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69765986/