2015-12-30 127 views
-1

此数据框中的第一列表示Twitter screenName。第二列包含推文中的@注释。本专栏中可能有多个@mention。在R中使用igraph绘制数据框

The dataframe looks like this

当我绘制它我得到连接到矢量不在YY1向量中的每个元素中的V1节点

The graph looks like this

我怎样才能显示每个节点和每个元件之间的连接?

+0

请勿张贴您的数据作为图像,请学习如何给予[重复的例子(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) – Jaap

+0

谢谢Jaap。下次会做。 – Bruce

回答

1

你可以尝试像这样

library(igraph) 
library(data.table) 
library(splitstackshape) 
dt <- data.table(V1=c("from1", "from2", "from3"), 
       yy1=c("@to1, @to2", "@to3, @to4", "@to5")) 
dt <- cSplit(dt, 2, ", ", "long")[, yy1:=sub("@", "", yy1, fixed=T)] 
dt %>% graph_from_data_frame %>% plot 

enter image description here

+0

非常感谢你lukeA。你的答案适合我。 – Bruce