大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
如何进行R语言网络图的分析,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
创新互联-专业网站定制、快速模板网站建设、高性价比顺河网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式顺河网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖顺河地区。费用合理售后完善,10余年实体公司更值得信赖。
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语言网络图的分析的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!