0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

igraphで異なるノード(頂点)の形の図を描く方法を調べています。

Last updated at Posted at 2019-12-07

前回igraphで描いた図について、異なる形のノードにする方法を調べています。
ノードの形を属性ごとに丸とか四角とかにしたいのですが、超ド素人のため方法がわかりません。
例によって恐縮ですが、不適切な点や他に良い方法などありましたらアドバイス頂けますと幸いです。

とりあえず、途中経過を書きます。

以下の図(project.csv)の読み込み。
スクリーンショット 2019-12-07 11.00.45.png

R
# project.csvの読み込み
project <- read.csv("project.csv", row.names = "PROJECT") 
# matrix()で行列に変換
project <- as.matrix(project)
# resultというオブジェクトを作成。元のprojectに対する転置行列をt()で作成し、%*% 演算子で元の行列に転置行列を掛けた内容を格納。
result <- project%*%t(project)

# 念のためresultの内容を確認。
> result
  a b c d e f
a 3 2 2 2 1 1
b 2 2 2 1 0 1
c 2 2 2 1 0 1
d 2 1 1 2 1 1
e 1 0 0 1 1 0
f 1 1 1 1 0 1

# igraphを読み込み
library("igraph")
# グラフオブジェクトを作成
result<-graph_from_adjacency_matrix(result, mode = "undirected",weighted=TRUE,diag = FALSE)
plot(result,edge.width = abs(E(result)$weight)*2)

この図ができます。
スクリーンショット 2019-12-07 11.00.58.png

この状態で、ノード(頂点)の情報を確認すると、以下の通りです。

R
V(result)
+ 6/6 vertices, named, from f0d6b10:
[1] a b c d e f

以下のHPによると、頂点の形として使えるのはvertex.shape “none”, “circle”, “square”, “csquare”, “rectangle”, “crectangle”, “vrectangle”, “pie”, “raster”, “sphere”の中から1つのようです。

そこで、例えば、a,b,cを四角、d,e,fを丸にしたい場合、以下のように入力してみました。

R
V(result)$shape <- c("square", "square","square", "circle", "circle", "circle")

出力するとこうなります。
スクリーンショット 2019-12-07 13.00.00.png

これで一応、異なる形にすることはできたのですが、ノードの形が増えるといちいち設定するのが面倒な気がします。
以下のHPの方法によれば属性ごとにノードの形を変えられるようですが、未だ解読できません...

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?