0

I am plotting in igraph and having difficulty plotting with an attribute for node size.

I have tried to add size attribute data from a csv file and indicate that it only applies to one column of my edgelist (I have a separate attribute file for the other column of the edgelist). But when I attempt to plot, I get an error message.

Edgelist data:

el[,"org"]=as.character(el[,"org"])
el[,"office"]=as.character(el[,"office"])
el=as.matrix(el)
g=graph.edgelist(el[,1:2])

Attribute for size:

V(g)$cont_amt=as.numeric(b$cont_amt[match(V(g)$name,b$org)])
V(g)$size=V(g)$cont_amt

V(g)$size <- ifelse(V(g)$size %in% el[,1], V(g)$size, NA)

Attempting to plot:
plot(g, layout=m, edge.arrow.size=.2, vertex.label.font=1, vertex.label.cex=.9, vertex.label.color="black")

I have been getting this error message when I plot: Error in plot.window(...) : need finite 'xlim' values

emilliman5
  • 5,816
  • 3
  • 27
  • 37

1 Answers1

0

This question relates to the comment in this one. Consider the following minimal working example:

library(igraph)
a <- 1:4
b <- letters[1:4]
edgelist <- cbind(a,b)
g <- graph_from_edgelist(edgelist)


Here I simply generated a random graph from an edgelist. The next step is to set the node size conditional on the apperance of the node names in the first column of the edgelist. The condition states that the name has to match the items in the first column. If 'yes', then increase the size to 16, if 'no' use the already specified size.

V(g)$size <- 8 
V(g)$size <- ifelse(test = V(g)$name %in% edgelist[,1], yes = 16, no =  V(g)$size)

This results in bigger sizes for the nodes from the first column of edgelist different sized nodes

Ben Nutzer
  • 1,082
  • 7
  • 15