ggnet2:错误:每个变量必须是1d原子向量或列表 [英] ggnet2 : Error: Each variable must be a 1d atomic vector or list
问题描述
我试图用ggnet2来可视化网络分析,但是遇到了一个错误。
我可以生成一个随机网络,
库(ggnet2)
库(网络)
库(sna)
库(ggplot2)
net = rgraph(10,mode =graph,tprob = 0.5)
net = network(net,directed = FALSE)
#顶点名称
network.vertex.names(net)= letters [1:10]
看起来是合理的
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
hyper = FALSE
loops = FALSE
multiple = FALSE
bipartite = FALSE
total edges = 28
missing edges = 0
non-缺少边缘= 28
顶点属性名称:
vertex.names
无边缘属性
$ p $但是,当我尝试运行..
ggnet2(net)
I g et a error
错误:每个变量必须是1d原子向量或列表。问题变量:x,y,xend,yend
$明确了这个错误是如何产生的,因为 net
是一个列表,它内的所有变量都是列表。我已经检查过,以确保我拥有所有必需的软件包,并且它们是最新的以及最新的R版本。
我刚试过 ggnetwork
,并且似乎也得到了类似的错误。
有关为何出现此错误的任何想法?
解决方案错误消息显示
错误:每个变量必须是1d原子向量或列表。问题
变量:x,y,xend,yend
code >如果您进行以下操作:
library(ggnetwork)
net < - ggnetwork(net)
class(net $ x)
你会发现 x
是一个列矩阵。您的其他组件也是如此。这样做
net $ x < - net $ x [,1]
net $ y < - net $ y [,1]
净$ xend< - 净$ xend [,1]
净$美元< - 美元$ yend [,1]
会将这些全部更改为1d原子向量和
ggplot(net,aes(x = x,y = y,xend = xend,yend = yend))+
geom_edges(aes(linetype =directed),color =grey50)
应该有效。你可以阅读更多关于如何使更漂亮的图形工作的捷径。
I am trying to use ggnet2 for visualizing a network analysis, but have run into an error with the vignette.
I can generate a random network,
library(ggnet2)
library(network)
library(sna)
library(ggplot2)
net = rgraph(10, mode = "graph", tprob = 0.5)
net = network(net, directed = FALSE)
# vertex names
network.vertex.names(net) = letters[1:10]
With an output that looks reasonable
>net
Network attributes:
vertices = 10
directed = FALSE
hyper = FALSE
loops = FALSE
multiple = FALSE
bipartite = FALSE
total edges= 28
missing edges= 0
non-missing edges= 28
Vertex attribute names:
vertex.names
No edge attributes
However, when I try to run..
ggnet2(net)
I get an error
Error: Each variable must be a 1d atomic vector or list. Problem variables: 'x', 'y', 'xend', 'yend'
I am not clear on how this error is arising in the vignette as net
is a list, and all variables within it are lists. I have checked to ensure that I have all the necessary packages and they are up-to-date as well as the most recent R version.
I just tried ggnetwork
and seem to get a similar error.
Any thoughts on why this errors is arising?
解决方案 The error message says
Error: Each variable must be a 1d atomic vector or list. Problem
variables: 'x', 'y', 'xend', 'yend'
If you do the following
library(ggnetwork)
net <- ggnetwork(net)
class(net$x)
you will find that x
is a one column matrix. The same is true for your other components. So doing
net$x <- net$x[,1]
net$y <- net$y[,1]
net$xend <- net$xend[,1]
net$yend <- net$yend[,1]
will change these all to 1d atomic vectors and
ggplot(net, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges(aes(linetype = "directed"), color = "grey50")
should work. You can read more about how to make ggnetwork work for prettier graphs.
这篇关于ggnet2:错误:每个变量必须是1d原子向量或列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!