如何进行R语言网络图的分析,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
nodes<-read.csv("Data_files/Dataset1-Media-Example-NODES.csv",
header=T,as.is = T)
links<-read.csv("Data_files/Dataset1-Media-Example-EDGES.csv",
header=T,as.is=T)
nodes
links
dim(nodes)
dim(links)
library(igraph)
net<-graph_from_data_frame(d=links,
vertices=nodes,directed=T)
net
library(ggraph)
ggraph(net)+
geom_edge_link(color="green")+
geom_node_point(color="red",size=10)+
theme_void()
ggraph(net,layout="lgl")+
geom_edge_link()+
theme_void()
ggraph(net,layout="lgl")+
geom_edge_fan()+
geom_node_point(color=V(net),size=8)+
theme_void()
ggraph(net, layout = 'linear') +
geom_edge_arc(color = "orange", width=0.7) +
geom_node_point(size=5, color="gray50") +
theme_void()
ggraph(net, layout="lgl") +
geom_edge_link(aes(color = type)) + # colors by edge type
geom_node_point(aes(size = audience.size)) + # size by audience size
theme_void()
ggraph(net, layout = 'lgl') +
geom_edge_arc(color="gray", curvature=0.3) +
geom_node_point(color="orange", aes(size = audience.size)) +
geom_node_text(aes(label = media), size=2, color="gray50", repel=T) +
theme_void()
教程中的例子可以重复出来,但是如何准备自己的数据呢?
尝试模仿
df1<-data.frame(id=c("A","B","C"))
df2<-data.frame(from=c("A","A","B","C"),
to=c("B","C","C","B"),
type=c("hyperlink","hyperlink","mention","mention"),
weight=c(30,10,20,50))
net1<-graph_from_data_frame(d=df2,vertices = nodes)
遇到报错
Error in graph_from_data_frame(d = df2, vertices = nodes) :
Some vertex names in edge list are not listed in vertex data frame
暂时还不知道如何解决!
看完上述内容,你们掌握如何进行R语言网络图的分析的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。