-1

I am attemping to create a weighted social network between a series of characters. I have manually created an adjacency matrix with weighted values: excel file of relationship values, 0-3. This has been linked to a separate file, in which attributes of the characters have been stored for later colouration.

My goal is to create a graph in TKplot, where vertice size is the degree centrality, and edge width is a function of their weight.

However, when using the igraph package to generate a simpler grapher, just to test the code, I noticed that I am generating additional vertices, which appear to be duplicates of the vertices (for example, see the clear and coloured squares marked "Rusty" on the right side of the image:practise igraph plot.

Here is the code I have written so far:

network_data<-read.csv('bbnmatrix2.csv',header=T, row.names=1, as.is=T)
bbnnames<-read.csv("bbnnames.csv", header=T, as.is=T)
net2 <- graph_from_incidence_matrix(network_data, directed = FALSE,
                                    mode = c("total"),
                                    multiple = FALSE,
                                    weighted = T,
                                    add.names = T)
plot(net2, vertex.label.color="black", vertex.label=bbnnames$name,
       vertex.label.cex=0.5, edge.color="black",
     vertex.color=clan, edge.width=E(net2)$weight,
     vertex.shapes=bbnnames$status).

I was expecting a plot of 67 vertices, but instead generated a plot of 134.

jpsmith
  • 11,023
  • 5
  • 15
  • 36
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Please [do not post code or data in images](https://meta.stackoverflow.com/q/285551/2372064) – MrFlick Apr 27 '23 at 14:06
  • Oh okay, got it, thats very helpful! Will change it (once I have read the examples you sent me). – peterkeenan Apr 27 '23 at 14:31

1 Answers1

0

Are you trying to make a bipartite network? graph_from_incidence_matrix() treats your input matrix as defining a bipartite network. I think you want graph_from_adjacency_matrix() instead.

nmaclaren
  • 73
  • 6