1

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

1 Answers1

0

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

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Another way is to control the size of edges instead of colours, what do you think? Is that possible? –  May 19 '22 at 20:54
  • 1
    @user4567794374545 I don't see an option to do that if you have to use edgebundle instead of ggplot. I'm going to be honest - you're tough to please! The method above is how the effect was achieved in the plot that prompted you to look at edgebundle, and it's what you asked for. I showed you how to achieve full customization in ggplot earlier (including line thickness), but edgebundle is just a bit limited in its customization options. Ultimately, it _is_ possible, since it is done with svg, but doing that would be a whole project rather than just an SO answer. – Allan Cameron May 19 '22 at 21:07
  • I believe using some kind of color scale would be possible though (intense colours for high values, pale colors for small values). That might look good. – Allan Cameron May 19 '22 at 21:09
  • Okay, that seems an option. But I don't know how to add or change the colour scale –  May 19 '22 at 21:12
  • @user4567794374545 from looking into it, this was never implemented in edgebundleR. It's now quite an old package and hasn't been updated for about 5 years. You can get some beautiful chord diagrams with `ggraph`, where things are fully customizable. Have you looked into that? – Allan Cameron May 19 '22 at 22:10
  • no, because edgebundleR fully meets my needs. I need the the exact interactive visualization as given by it –  May 19 '22 at 22:49
  • https://stackoverflow.com/questions/72317065/how-to-build-interactive-chord-circle-neural-diagram-via-ggraph-ggplotly-in-r –  May 20 '22 at 10:13