0

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!

user2554330
  • 37,248
  • 4
  • 43
  • 90

1 Answers1

0

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)))
emilliman5
  • 5,816
  • 3
  • 27
  • 37
  • Thank you so much. Actually I didn't use all of your codes but you gave me an opinion and new perspective. I need to ask one more thing, is it possible that display a node with both it's name and attribute label? – Ayse Kubra Mar 11 '18 at 19:49
  • Sure you can in the call to `plot` you can add something like`vertex.label=paste0(V(g)$name, V(g)$attribute)` – emilliman5 Mar 11 '18 at 22:31