The ggnet2 library allows to build network chart. Your data must be formatted in one of these formats. Then it will be transformed into a **network object** using the network library.

**A-B-C-D, E-A-E-A**

**1- Adjacency matrix**

An **adjacency matrix** is a square matrix where individuals are the same in row and columns of the matrix. It’s typically the kind of matrix you get when calculating the correlation between each pair of individual. In this example, we have 1 connection from E to C, and 2 connections from C to E.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Libraries library(GGally) library(network) library(sna) library(ggplot2) # Create data set.seed(10) data=matrix(sample(0:2, 25, replace=TRUE), nrow=5) colnames(data)=rownames(data)=LETTERS[1:5] # Make a network object my_net = network(data, directed = FALSE, matrix.type="adjacency") # Plot it ggnet2(my_net, label = TRUE) |

**2- Incidence matrix**

An **incidence matrix** does not necessarily have the same individuals in row and colum. By default, it is directed from rows to columns.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# Libraries library(GGally) library(network) library(sna) library(ggplot2) # create data set.seed(1) data=matrix(sample(0:2, 15, replace=TRUE), nrow=3) colnames(data) <- letters[1:5] rownames(data) <- LETTERS[1:3] # create the network object my_net=network(data, matrix.type = "bipartite", ignore.eval = FALSE, names.eval = "weights") # plot it ggnet2(my_net, label = TRUE) |

**3- Edge List
**

The **edge list** is a data.frame listing all the connections.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# Libraries library(GGally) library(network) library(sna) library(ggplot2) # create data: links=data.frame( source=c("A","A", "A", "A", "A","F", "B"), target=c("B","B", "C", "D", "F","A","E") ) # create the network object my_net = network(links, directed = FALSE, matrix.type="edgelist") # plot it ggnet2(my_net, label = TRUE) |

Not what you are looking for ? Make a new search !

`[mediatagger]`

## Leave a Reply

Be the First to Comment!