Suppose I have a dataset in R indicating the individuals within groups. Here is an example:
grp <- c(1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5)
ind <- c("A", "C", "D", "B", "C", "D", "E", "A", "D", "E", "B", "F", "E", "A", "F")
data.frame(grp, ind)
So, the data look like this:
grp ind
1 1 A
2 1 C
3 1 D
4 2 B
5 2 C
6 2 D
7 2 E
8 3 A
9 3 D
10 3 E
11 4 B
12 4 F
13 4 E
14 5 A
15 5 F
So, group 1 is composed of individuals (A, C, D), group 2 is composed of individuals (B, C, D, E), and so on. I would like to create a network graph that shows how individuals are connected with each other. Within a group, all individuals are connected by edges. The thickness of the edges should reflect how often two individuals are connected to each other.
With:
pairs <- do.call(rbind, sapply(split(ind, grp), function(x) t(combn(x,2))))
I can obtain a matrix with all pairwise edges, which I can plot with the igraph
package:
library(igraph)
plot(graph.edgelist(pairs, directed=FALSE), edge.curved=FALSE)
But is there a way of making the thickness of the edges proportional to how often a particular pairing occurred?