'Edge Size in R based on frequency

Given a matrix with multiple edges (that is, the same two nodes are connected multiple times, over time), I'd like to be able to use the frequency of that edge occurring to calculate a weight for the visualization. is there a way to do this?

For example if the edge list came from:

#create dataset
from<-c("a","a","a","b","b","c")
to<-c("b", "b", "c", "a", "a", "a") 
df<-data.frame(from,to)
# get names
from.names <- df %>% select(from) %>% unique() %>% rename(name=from)
to.names<- df %>% select(to) %>% unique() %>% rename(name=to)
edge_names<- rbind(from.names, to.names) %>% unique %>% arrange(name)
#create network
nw<-graph_from_data_frame(df, vertices=edge_names, directed=F)

#graph the network 
graph1<-ggraph(nw, layout="stress") + 
              geom_edge_link(color="grey") +
              geom_node_point(aes(size =3))+ 
              geom_node_text(aes(label=name, fontface="bold"), repel=T)+
              theme_void()
graph1
#show frequency of edges
nw%>% as_adjacency_matrix()

then the resulting edge attributes should show a wider edge for a to b as this occurred twice, and a narrower edge for a to c as this occurred once. I'm using Igraph.



Solution 1:[1]

We can try attributes and retrieve vnames to get the "names" of edges, and use table to summarize the frequency

> table(attributes(E(nw))$vnames)

a|b a|c
  4   2

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 ThomasIsCoding