您好,登錄后才能下訂單哦!
如何進行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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。