本文介绍了在Riggraph中使用组创建变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的生殖示例代码.
below are my reproductive sample codes.
sender_code <- c(12 ,1 ,6 ,19 ,7 ,8 ,3 ,17 ,13 ,10 ,4 ,9 ,2 ,5
,15 ,11 ,16 ,20 ,14 ,18)
receiver_code <- c( 20 ,16 ,7 ,3 ,4 ,11 ,8 ,2 ,10 ,12 ,17 ,5 ,1 ,18 ,13 ,9 ,6 ,15 ,19 ,14)
sender_country <- ifelse(sender_code<6,"Phil",
ifelse(sender_code<10,"Japan",
ifelse(sender_code<16,"Brazil",
"Norway"
)
)
)
receiver_country <- ifelse(receiver_code<6,"Phil",
ifelse(receiver_code<10,"Japan",
ifelse(receiver_code<16,"Brazil",
"Norway"
)
)
)
message<- data.frame(sender_code,receiver_code,sender_country,receiver_country
我想将每个发送方连接到每个接收方,然后根据其国家/地区对它们进行颜色编码,如下图所示:
I want to connect each sender to the each receiver and then colour code them based on their country like the this graph:
http://revolution-computing.typepad.com/.a/6a010534b1db25970b017c379af59c970b- pi
问题是我不知道igraph上的哪些函数可以基于我的数据创建这种图.
Problem is I do not know what function on igraph that can create that kind of graph base on my data.
预先感谢
推荐答案
尝试一下:
library(igraph)
with(message,
plot(graph.data.frame(message),
vertex.color = sender_country,
vertex.label.color = "white",
edge.color = sender_country)
)
?plot.igraph
下的更多信息.
这篇关于在Riggraph中使用组创建变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!