0
votes

I would like to set my network nodes size to degree centrality and the distribution on the x axis to eigenvector centrality while I distribute an attribute on the y axis. I have the following code:

    u <- layout_with_dh(G1)

Aff <- "dashed"
Inf <- "solid"
Trig <- "dotted"
edge.lty = E(G1)$lty <- E(G_Network)$Type

start <- ends(G1, es = E(G1), names = F) [, 1]
edge.col <- V(G1)$color[start]

el <- c("Magenta", "olive drab", "spring green", "coral", "golden rod", "corn flower blue", "cyan", "Brown")
V(G1)$color <- el[V(G1)$Property]

EG <- eigen_centrality(G1, directed = T, scale = T, weights = NULL)


plot(EG, log = "xy", x = 0:max(EG), y = V(G1)$Pro, pch = 19, cex = 1, edge.width = 2, edge.arrow.size = .9, vertex.label.cex = 1, vertex.label.color = "black", vertex.label.font = 2, edge.curved = .5, edge.lty = E(G1), vertex.size = 3*igraph::degree(G1, mode = "out"), edge.color = edge.col, rescale = F, layout = u*1.3)
plot()

Everything runs except the last code block. What do I need to do?

here is a printable sample of the network using 'dput(G1)' and a print of the graph:

structure(list(22, TRUE, c(0, 1, 3, 5, 4, 4, 3, 9, 11, 3, 13, 15, 16, 14, 18, 20, 20), c(1, 2, 4, 4, 6, 7, 8, 10, 12, 13, 14, 13, 17, 16, 19, 16, 21), c(0, 1, 2, 6, 9, 4, 5, 3, 7, 8, 10, 13, 11, 12, 14, 15, 16), c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 10, 13, 15, 12, 14, 16), c(0, 1, 2, 2, 5, 7, 8, 8, 8, 8, 9, 9, 10, 10, 11, 12, 13, 14, 14, 15, 15, 17, 17), c(0, 0, 1, 2, 2, 4, 4, 5, 6, 7, 7, 8, 8, 9, 11, 12, 12, 14, 15, 15, 16, 16, 17 ), list(c(1, 0, 1), structure(list(), .Names = character(0)), list(name = c("P702", "P617", "P616", "P619", "P701", "P212", "P608", "P625", "P807", "P623", "P101", "P613", "P801", "P606", "P603", "P602", "P615", "P252", "P251", "P238", "P604", "P624" ), Property = c(7L, 6L, 6L, 7L, 7L, 2L, 6L, 6L, 8L, 6L, 1L, 6L, 8L, 6L, 6L, 6L, 6L, 2L, 2L, 2L, 6L, 6L), Pro = c(5, -4, 7, -6, 6, 2, 3, -5, -4, 2.5, 1.6, 6, 3, 1, -2, -5, 4.5, 2, -3, 2, 2, 1)), list(Type = c("Trig", "Aff", "Inf", "Inf", "Aff", "Aff", "Trig", "Inf", "Inf", "Inf", "Aff", "Aff", "Inf", "Inf", "Aff", "Inf", "Inf"))), ), class = "igraph") IGRAPH 0856078 DN-- 22 17 -- + attr: name (v/c), Property (v/n), Pro (v/n), Type (e/c) + edges from 0856078 (vertex names): [1] P702->P617 P617->P616 P619->P701 P212->P701 P701->P608 P701->P625 P619->P807 P623->P101 P613->P801 P619->P606 P606->P603 P602->P606 [13] P615->P252 P603->P615 P251->P238 P604->P615 P604->P624

Thanks. personally, I prefer perusing the table version, I am new to r and unsure how to attach it, but here:

Vertex.1 Vertex.2 Type

P702 P617 Trig
P617 P616 Aff
P619 P701 Inf
P212 P701 Inf
P701 P608 Aff
P701 P625 Aff
P619 P807 Trig
P623 P101 Inf
P613 P801 Inf
P619 P606 Inf

P606 P603 Aff
P602 P606 Aff
P615 P252 Inf
P603 P615 Inf
P251 P238 Aff
P604 P615 Inf
P604 P624 Inf

and the vertices sample data:

Vertex Property Pro

P702 7 5.0
P617 6 -4.0
P616 6 7.0
P619 7 -6.0
P701 7 6.0
P212 2 2.0
P608 6 3.0
P625 6 -5.0
P807 8 -4.0
P623 6 2.5

P101 1 1.6
P613 6 6.0
P801 8 3.0
P606 6 1.0
P603 6 -2.0
P602 6 -5.0
P615 6 4.5
P252 2 2.0
P251 2 -3.0
P238 2 2.0

P604 6 2.0
P624 6 1.0

1
Could you please give us some sample data to work with? Use dput(G_Network) to get a printable version of your graph and paste it into your question. It would be good if you read How to ask a good questionG5W
thanks a million G5W for the response. I have edited the question and added the sample data as instructed. hope it is clearer, will also take a look at the question guide. I would attach a sample of the edge list and vertices list but don't know how to do that yet. so, is there a way to map my eigenvector values and arrange them on x axis, otherwise I would settle for a way to assign them to alpha values? thanks any help is appreciated.AyDee
It looks like the output of your dput was truncated.G5W
thanks @GSW I was unsure what to do about the dput output, so I tried to copy and paste a print out of the edge and vertices sample data. hope it helps, there are 22 vertices and 17 edges in this sample. thanks very muchAyDee
apologies for the typo: @G5WAyDee

1 Answers

0
votes

For those who want to work with this, an easier to execute version of the data is at the end of the post.

I am going to assume that you want to layout the size and position of the nodes.
vertex size = degree centrality
x-axis position = eigenvalue centrality
y-axis position = Pro (from your vertex properties)

The vertex size is relatively simple. Just specify the vertex.size parameter when plotting. However, the degrees of your vertices range from 1 to 4, mostly 1's. That is too small to use directly as the vertex size, so you will want to scale the values first. I picked something to look nice.

VS = 6 + 5*degree(g)
plot(g, vertex.size=VS)

graph with vertex size specified

To position the nodes, you need to specify a layout. That is simply a n x 2 matrix with the x-y position where you want the vertices plotted. Again, a bit of scaling may be helpful.

x = round(10*eigen_centrality(g)$vector, 2)
y = vertex_attr(g, "Pro")
LO = cbind(x,y)
plot(g, vertex.size=VS, layout=LO)

Size and position specified

However, I suspect that you will want something that you did not specify and is just slightly harder to get - labeled axes so that you can read the x-y coordinates off the graph. This is a bit more work because the default igraph plotting rescales the position of the graph so that both axes run between +1 and -1. To keep the original scale, use rescale=FALSE. You have to specify the x-y limits and add the axes yourself. That also requires adjusting the vertex sizes.

plot(g, vertex.size=7*VS, layout=LO, rescale=F, 
    xlim=range(x), ylim=range(y))
axis(side=1, pos=min(y)-1)
axis(side=2)

Final version of graph

Data and graph creation

EL = read.table(text="Vertex.1 Vertex.2 Type
P702 P617 Trig
P617 P616 Aff
P619 P701 Inf
P212 P701 Inf
P701 P608 Aff
P701 P625 Aff
P619 P807 Trig
P623 P101 Inf
P613 P801 Inf
P619 P606 Inf
P606 P603 Aff
P602 P606 Aff
P615 P252 Inf
P603 P615 Inf
P251 P238 Aff
P604 P615 Inf
P604 P624 Inf",
header=T)

VERT = read.table(text="Vertex Property Pro
P702 7 5.0
P617 6 -4.0
P616 6 7.0
P619 7 -6.0
P701 7 6.0
P212 2 2.0
P608 6 3.0
P625 6 -5.0
P807 8 -4.0
P623 6 2.5
P101 1 1.6
P613 6 6.0
P801 8 3.0
P606 6 1.0
P603 6 -2.0
P602 6 -5.0
P615 6 4.5
P252 2 2.0
P251 2 -3.0
P238 2 2.0
P604 6 2.0
P624 6 1.0",
header=T)

g = graph_from_data_frame(EL, directed=FALSE, vertices=VERT)