igraphライブラリを読み込む.
> library(igraph)10ノードのツリーグラフを作成する.
> g<-graph.tree(10)グラフをレイアウトする.
> summary(g)
Vertices: 10
Edges: 9
Directed: TRUE
No graph attributes.
No vertex attributes.
No edge attributes.
> g
Vertices: 10
Edges: 9
Directed: TRUE
Edges:
[0] 0 -> 1
[1] 0 -> 2
[2] 1 -> 3
[3] 1 -> 4
[4] 2 -> 5
[5] 2 -> 6
[6] 3 -> 7
[7] 3 -> 8
[8] 4 -> 9
> lay<-layout.fruchterman.reingold(g)
> layここまでの作業をファイル保存する.
[,1] [,2]
[1,] 0.5750165 -0.7339218
[2,] 4.2972271 -0.9157740
[3,] -2.8644359 0.1233019
[4,] 5.7313203 2.7760283
[5,] 5.3732637 -4.4586431
[6,] -3.4715509 3.4824008
[7,] -4.1404984 -2.9629157
[8,] 4.2804038 5.9832150
[9,] 8.9190178 2.4068283
[10,] 4.1109849 -7.2698722
> save(g,lay,file="test.dat")グラフを描画する.
> plot(g,layout=lay)
> png("plot.png",width=400, height=400,pointsize=12)
> plot(g,layout=lay)
> dev.off()
null device
1
0 件のコメント:
コメントを投稿