根据图像创建igraph

时间:2017-04-22 18:49:22

标签: r igraph

我需要使用看起来像这样的数据集创建图表。代码呈现的图形需要"缝合"在一起并且类似于下面的图片。无法更改数据框。

df <- data.frame(col0 = "Animals",
col1 = c(NA, "1", "1", "1"),
col2 = c(NA, "3", "3", "3"),
col3 = c(NA, "Cat Dog Wolf", "Cat Dog Wolf", "Cat Dog Wolf"),
col4 = c(NA, "1", "2", "3"),
col5 = c(NA, "Cat", "Dog", "Wolf"),
col6 = c(NA, "Feline", "Canis", "Canis2")) 


sub <-df[!is.na(df$col3),]
df <-df[-c(1), ]
df <-df[c('col6', 'col5')]

df$'new_col' <- paste(df$'col6',df$'col5')
#creating a new col with col5 and col6 info

df <-  rbind(df[4:5,c(1,4)],data.frame('col3'=df[4,6],'new_col'=df[5,6]))
#this is where I get lost when tring get vertex

names(df) <-c('from', 'to')
abc <-union(df$to, df$from)
g <-graph.data.frame(df, directed = TRUE, vertices = abc)
plot(g, vertex.size = 20, vertex.label.dist = 0.5, vertex.color = c("lightblue","red","green","white"),
edge.arrow.size = 0.5, layout = layout.reingold.tilford(g))

enter image description here

0 个答案:

没有答案