遺伝子の変異とかを扱うときに便利かもしれないし気になるので使ってみた。
igraph
何の変哲もないランダムなグラフ
install.packages("igaph") library("igraph") mat <- matrix(nc=10, nr=10) for (i in 1:10) { mat[i,] <- rbinom(n=10, size=1, prob=c(0.5, 0.5)) mat[i, i] <- 0 } g <- graph.adjacency(mat) g <- as.undirected(g) plot(g) plot(g, layout=layout.circle)
山田先生のブログ記事のもやってみる。
# igraphはエッジの名前が1始まりに変わったらしい edge.list <- matrix(c(0,1, 0,2, 0,3, 2,3, 3,4), byrow=T) + 1 edge.list g <- graph.edgelist(el=edge.list, directed=F) # 隣接行列 get.adjacency(g) # エッジリスト get.edgelist(g) # 隣接した頂点 get.adjlist(g) g <- graph.adjlist(get.adjlist(g)) # これからグラフを作ってみる g <- as.undirected(g) # 元通り! # 辺同士の関係 get.adjedgelsit(g) shortest.paths(g) vcount(g) # 辺の数 ecount(g) # 頂点数
kinship2
install.packages("kinship2") library("kinship2") # 最近流行りの家系図 fam <- data.frame(id=seq(1, 4), dad=c(0, 0, 0, 3), mom=c(0, 0, 0, 2), sex=c(0, 1, 0, 0), affected=c(0, 0, 0, 1)) plot(pedigree(id=fam$id, dad=fam$dad, mom=fam$mom, sex=fam$sex, affected=fam$affected)) # ぐぬぬ...Did not plot the following people: 1
どうやら親子関係のない人はプロットされないらしい(仕様)。