r - 根据包含参与者之间关系的数据框列更改边缘厚度

标签 r plot igraph

此代码根据参与者和关系的数据框绘制图表。

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)

结果是:

enter image description here

我想根据 relations$friendship 的值更改弧的粗细(而不是长度)。

最佳答案

试试

plot(g,edge.width = E(g)$friendship, edge.arrow.size = E(g)$friendship)

enter image description here


请注意,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/

相关文章:

r - 从组成员数据创建加权图

r - lmer 与 gls 中的缺失值

根据另一个变量中的 TRUE 或 FALSE 重新编码

r - ggplot2 时间序列图,带有颜色编码的风向箭头

python - 如何为 Mayavi 的网格图使用掩码?

python - 如何将顶点属性添加到使用 TupleList 创建的图形?

r - igraph 中的地理布局

R:动画包的新错误:convert.exe 不再在 Imagemagick 中

r - 为最小-最大范围创建 geom_ribbon

matlab - 从 MATLAB 中的 GUI 更改图形的 x 轴和 y 轴颜色