我有一些非常简单的谱系数据,我想以图形方式进行可视化。示例数据在这里
我已经尝试过 kinship2,但没有成功 -请参阅此处了解 kinship2 以前的问题
我也一直在尝试使用 igraph,但无法完全正确地绘制图表。我已经通过以下代码成功地获得了女性血统的良好表现。
library(igraph)
library(dplyr)
GGM_igraph <- read.csv("example_data.csv")
mothers=GGM_igraph[,c('Ring','Mother','famid')]
fathers=GGM_igraph[,c('Ring','Father','famid')]
links<-left_join(mothers, fathers)
g=graph.data.frame(links)
这个脚本最初来自这个问题
G_Grouped = g
E(G_Grouped)$weight = 1
## Add edges with high weight between all nodes in the same group
for(i in unique(V(g)$famid)) {
GroupV = which(V(g)$famid == i)
G_Grouped = add_edges(G_Grouped, combn(GroupV, 5), attr=list(weight=10))
}
## Now create a layout based on G_Grouped
set.seed(567)
LO = layout_with_fr(G_Grouped)
## Use the layout to plot the original graph
par(mar=c(0,0,0,0))
# then plot the graph
plot(g, vertex.color=links$famid, layout=LO,
vertex.size = 8,
vertex.label.cex=.7,
vertex.label.color = "black",
edge.arrow.size = 0.25,
edge.arrow.mode = 1)
我想做的是:1)将男性包括在同一个图表中,因为他们中的一些人在他们的一生中有多个女性的后代 2)手动为每个家庭分配颜色。目前它是自动的,然后为母亲(大多数没有家庭,因为他们是创始人)分配随机颜色,并且由于默认调色板中没有足够的颜色,它正在重复使用一些颜色。
