0

I am trying to subset an igraph plot to display certain nodes based on a given vertex attribute. I have to subset them in the plot output to preserve the layout for the vertices. My code is the following:

plot.igraph(graph, layout=lo, vertex.label=NA, rescale=T, vertex.size = 4) %>% 
  tidygraph::activate(nodes) %>% 
  filter(period == 1)

But I receive the following error:

Error in UseMethod("activate") : 
no applicable method for 'activate' applied to an object of class "NULL"

How can I subset the graph based on the vertex attribute "V(graph)$period", maintaining the vertices' layout?

flâneur
  • 633
  • 2
  • 8

1 Answers1

-1

Observe that class(plot(graph)) returns NULL.

Update, calculate subset as follows.

## Random example.
set.seed(20)
g           <- make_ring(20)
V(g)$period <- sample(2, vcount(g), replace=TRUE)
V(g)$name   <- V(g)

## Calculate subset of vertices
## and plot subgraph.
vvv         <- V(g)[which(V(g)$period==1)] 
g2          <- subgraph(g, vvv)
plot(g2)
clp
  • 1,098
  • 5
  • 11