I am using igraph and I would like to use the mark.groups
function to specify some groups within the network. The function requires groups to be specified by vectors of numerical Node identifiers - e.g.mark.groups = c(1,5,7)
.
I have a list of groups and associated in a dataframe format:
groups
Group_ID Node_ID
1 1
1 2
1 3
2 4
2 5
Rather than type these by hand in the mark.groups function, I split the dataframe into a list of sub-dataframes:
members <- groups %>%
group_split(Group_ID, keep = FALSE)
I am then trying to refer to these elements when plotting the chart. This code works:
plot(net,
mark.groups = c(members[[1]], members[[2]])
)
But I would like to be able to refer to all the split-out elements without having to type each individually. I have tried this, but it throws a Error in members[[1]]:members[[2]] : NA/NaN argument
error:
plot(net,
mark.groups = c(members[[1]]:members[[2]])
)
I thought it might be possible to create a list of the names of the elements using this:
mem_count <- length(members)
mem_list <- paste("members[[", 1:mem_count[1], "]],", sep = "")
and then refer to them in the plot()
function:
plot(net,
mark.groups = memlist
)
But that doesn't seem to work either, giving this error Error in simple_vs_index(x, ii, na_ok) : Unknown vertex selected
.
Any ideas much appreciated.