igraph 网络布局
igraph 包提供了多种内置的网络可视化布局算法。针对不同规模的网络,不同布局在表达网络结构方面的效果可能不同。理想情况下,最佳布局应尽量减少网络中边与边的相互交叉。在本练习中,您将探索多个默认布局算法。每次重新运行同一种布局的绘图代码,结果都会略有不同。多试几次,有助于为您的网络找到更美观的可视化效果。
本练习是课程的一部分
R 中的网络分析
练习说明
- 在 plot 函数中,将
layout参数改为layout_in_circle(),绘制圆形网络。 - 在 plot 函数中,将
layout参数改为layout_with_fr(),绘制 Fruchterman-Reingold 布局的网络。 - 您也可以通过为每个顶点提供一组 (x, y) 坐标矩阵来指定布局。这里使用
layout_as_tree()生成坐标矩阵m,然后在plot()中把m传给layout参数进行绘制。 - 选择合适的布局可能让人无从下手。好在
igraph提供了layout_nicely(),可为给定图对象自动选择更合适的布局函数。请使用该函数生成矩阵m1,并用这些坐标绘制网络。
交互式实操练习
通过完成这段示例代码来试试这个练习。
library(igraph)
# Plot the graph object g1 in a circle layout
plot(g1, vertex.label.color = "black", layout = ___(g1))
# Plot the graph object g1 in a Fruchterman-Reingold layout
plot(g1, vertex.label.color = "black", layout = ___(g1))
# Plot the graph object g1 in a Tree layout
m <- ___(g1)
plot(g1, vertex.label.color = "black", layout = m)
# Plot the graph object g1 using igraph's chosen layout
___ <- layout_nicely(___)
plot(___, vertex.label.color = "black", layout = ___)