rplotigraphbipartitevertex-attributes

different vertex shapes for each vertex of decomposed graph


I have a very large bipartite network model that I created from 5 million lines of a dataset. I decompose my network model because I can not draw a graph of this size. Now all I need is to plot the decompose graphics one by one. There is no problem with that. But I want to draw the graph with a shape according to the attributes of each node. For example, I want a square for the "A" attributes on my graph G, and a triangle for the "B" attributes. In addition to this I want to add vertex labels by attributes. Here is my codes to plot first component of graph after creating bipartite G and its work:

    components <- decompose(G)
    plot(components[[1]]) 

I tried something like this to adding labels and changing vertex shapes according to graph attributes but it didn't work:

    plot(components[[1]], vertex.label= V(G)$attributes, 
    vertex.shape=c("square", "triangle"))

Does anyone can help me, I'm stuck. Thank you so much!


Solution

  • the components function returns a list of vertices which make up a component. So you need to traverse the list, create a subgraph and plot. As for plotting attributes you need to provide a reproducible example for us to help.

    library(igraph)
    set.seed(8675309)
    
    g <- sample_gnp(200, p = 0.01)
    V(g)$name <- paste0("Node", 1:vcount(g))
    V(g)$shape <- sample(c("circle","square"), vcount(g), replace = T)
    clu <- components(g)
    grps <- groups(clu)
    
    lapply(grps, function(x) plot(induced_subgraph(g, x)))