I have this network graph in R:
library(igraph)
# create the data frame
my_data <- data.frame(to = c(1,2,3,4,2,4,1,1,1,7,7), from = c(2,2,2,2,6,5,7,8,9, 10,11))
# create the igraph object
my_graph <- graph_from_data_frame(my_data, directed = FALSE)
# plot the graph
plot(my_graph)
In a previous question (All Nodes of Degree "N" that can be reached from Some Node), I learned how to find out the number of nodes that can be reached from a specific node within a radius = n:
# neighbors of degree = 3 from node = 1
q = ego(my_graph, 3, "1")
[[1]]
+ 11/11 vertices, named, from 8e85769:
[1] 1 2 7 8 9 3 4 6 10 11 5
My Question: I am trying to plot this "q" object - however, when I try to make a plot, I get the following error:
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
I tried to troubleshoot this problem and I realized that this is likely happening because the ego()
function is only returning the nodes and not preserving the edge information.
I tried a workaround with the following code:
plot(induced.subgraph(graph=my_graph,vids=as.numeric(q[[1]])))
The code seems to be working, but am I doing this correctly?