I am attempting to create a network map using various packages and methods.
Using this as a guide, I have copied and pasted each step
http://minimaxir.com/notebooks/interactive-network/
However, when I try to view plot it comes up with this error:
Error: Each variable must be a 1d atomic vector or list. Problem variables: 'x', 'y', 'xend', 'yend'
Clearly this error has not come up on that example and it works fine for the creator but it also happens when I have tried using my own data too.
There aren't any useful answers to this ggnet2 : Error: Each variable must be a 1d atomic vector or list
Any idea what the issue could be?
I have a feeling it may be to do with the origin and destination variables being characters, however I don't know if they can be converted to numeric and I wouldn't actually want them as numeric as I would like the name of origin and destination to be displayed.
library(dplyr)
library(nycflights13)
library(igraph)
library(sna)
library(ggnetwork)
df_edges <- flights %>% group_by(origin, dest) %>% summarize(weight = n())
net <- graph.data.frame(df_edges, directed = T)
V(net)$degree <- centralization.degree(net)$res
df_net <- ggnetwork(net, layout = "fruchtermanreingold", weights = "weight", niter = 5000)
ggplot(df_net, aes(x = x, y = y, xend = xend, yend = yend)) + geom_edges(size = 0.4, alpha = 0.25) + geom_nodes(aes(size = degree, text = vertex.names)) + ggtitle("Network Graph of U.S. Flights Outbound from NYC in 2013") + theme_blank()
The issue reported in the question seems to have vanished, as the code posted in the question runs without any issue on my end (see session info below for the package versions).
It is likely that the issue had to do not with
ggnetwork
, which expects a data frame, but withtibbles
(used internally bydplyr
), which is stricter in what it accepts as a 'tidy' data frame.