'How to make neural edges more dynamic in neural plot?

I have data which represents transit between UK cities.

  1. Transit: if there is a transit between these two cities = 1, otherwise =0
  2. ave.pas: average number of passengers

.

library(plotly) library(ggraph) library(tidyverse) library(tidygraph) library(igraph) library(edgebundleR)

   df2 <- data.frame (City1  = c("London", "London", "London", "London" ,"Liverpool","Liverpool","Liverpool" , "Manchester", "Manchester", "Bristol"),
                          City2 = c("Liverpool", "Manchester", "Bristol","Derby", "Manchester", "Bristol","Derby","Bristol","Derby","Derby"),
                          Transit = c(1,0,1,1,1,1,1,1,0,1),
                          ave.pas = c(10,0,11,24,40,45,12,34,0,29))

df:

        City1      City2 Transit ave.pas
1      London  Liverpool       1      10
2      London Manchester       0       0
3      London    Bristol       1      11
4      London      Derby       1      24
5   Liverpool Manchester       1      40
6   Liverpool    Bristol       1      45
7   Liverpool      Derby       1      12
8  Manchester    Bristol       1      34
9  Manchester      Derby       0       0
10    Bristol      Derby       1      29

Now I plot circular network:

df <- subset(df2, Transit== 1, select = c("City1","City2"))
edgebundle(graph.data.frame(df),directed=F,tension=0.1,fontsize = 10)

My goal is to set the size or colour's intensitvity of edges based on the corresponding value in 'ave.pas' variable from the dataset

linked links: link1 link2 link3 link4

(Plot must be made using edgebundle() function) enter image description here



Solution 1:[1]

The intensity of the edges in the linked plots appears to be a function of the number of edges joining the vertices. We can make the number of edges equal to the number of passengers, but the problem here is that after a few lines are plotted on top of each other, the intensity stops increasing. It is therefore good for showing the difference between, say, 1 and 3 edges, but the difference between 10 and 30 is much less obvious. As a compromise, we can make the number of edges approximately proportional to the number of passengers. One way to do this is to create the graph from an adjacency matrix:

cities <- unique(c(df2$City1, df$City2))

m <- matrix(0, nrow = length(cities), ncol = length(cities), 
            dimnames = list(cities, cities))

for(i in seq(nrow(df2))) m[df2[i, 1], df2[i, 2]] <- df2[i, 4]

m <- m/min(m[m > 0])

edgebundle(graph_from_adjacency_matrix(m))

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Allan Cameron