本文介绍了颜色传说不会出现在ggnet2阴谋的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图绘制网络 g : > ; g 网络属性: vertices = 866 directed = TRUE hyper = FALSE loops = FALSE multiple = FALSE bipartite = FALSE total edges = 5310 缺少边缘= 0 非缺失边缘= 5310 顶点属性名称:颜色度成员vertex.names 边缘属性名称未显示 g node membership以下列频率出现: >表格(g%v%会员资格) 1 2 3 4 5 19 44 11 196 596 当我使用优秀的 ggnet2 包和下面的函数时,一个没有图例的图返回,尽管 解决方案我的猜测是您将数值顶点属性传递给 ggnet2 ,然后了解它作为颜色值的矢量。 简短回答: 将您的成员资格属性转换为字符字符串,您就可以了。 长答案: 比较以下示例中的两个图表以获得差异: 库(GGally)库(ggplot2)库(网络)库(sna)$ (样本(10))g%v%成员资格< - 样本(1:5,10,替换=真)g%v% (g) 表格(g%)g%v%degree v%membership) ##您的图 ggnet2(g,color =membership,size =degree)+ guides(size = FALSE) ##您的图形,会员变量为字符串 ggnet2(g,color =membership_string,size =degree)+ guides(size = FALSE) 如果您想要在您的情节中使用可区分的颜色而不是灰度级别, ng像这样: ggnet2(g,color =membership_string,size =degree,color.palette =Set1 )+ guides(size = FALSE) 另外,我可以推荐你给尝试使用 ggnetwork 软件包,功能? I am trying to plot the network g:> g Network attributes: vertices = 866 directed = TRUE hyper = FALSE loops = FALSE multiple = FALSE bipartite = FALSE total edges= 5310 missing edges= 0 non-missing edges= 5310 Vertex attribute names: color degree membership vertex.names Edge attribute names not showng node "membership" occurs with the following frequency:> table(g %v% "membership") 1 2 3 4 5 19 44 11 196 596When I use the excellent ggnet2 package and the following function, a plot without a legend returns, although the documentation suggests a plot for node size, color, etc. is automatically generated (see the node legends section):ggnet2(g_new, color = "membership", size = "degree") + guides(size = F) 解决方案 My guess is that you are passing a numeric vertex attribute to ggnet2, which then understands it as a vector of color values.Short answer:Turn your membership attribute into a character string, and you will be fine.Long answer:Compare the two graphs in the example below to get the difference:library(GGally)library(ggplot2)library(network)library(sna)g <- network(rgraph(10))g %v% "membership" <- sample(1:5, 10, replace = TRUE)g %v% "membership_string" <- as.character(g %v% "membership")g %v% "degree" <- degree(g)gtable(g %v% "membership")## Your graphggnet2(g, color = "membership", size = "degree") + guides(size = FALSE)## Your graph, with the membership variable as a stringggnet2(g, color = "membership_string", size = "degree") + guides(size = FALSE)If you want distinguishable colors instead of grayscale levels in your plot, you probably want something like this:ggnet2(g, color = "membership_string", size = "degree", color.palette = "Set1") + guides(size = FALSE)Also, may I recommend that you give a try to the ggnetwork package, which has additional functionalities? 这篇关于颜色传说不会出现在ggnet2阴谋的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-09 19:05