# Network Visualisation With R

### The main reason why

After all, I am still an Internal Auditor. Therefore I often face one of the typical internal auditors problems: understand links between people and companies, in order to discover the existence of hidden communities that could expose the company to unknown risks.

In order to address this problem I am developing Linker, a lean shiny app that take 1 to 1 links as an input and gives as output a network map:

[caption id=“attachment_324” align=“aligncenter” width=“300”] click the picture to reach the app[/caption]

**Linker **is packed with a demo network, but you can easily load your dataset following the tutorial below.

### how to use linker ( and some code specs)

the one that follow is a tutorial with some focus on code, if you are interested in giving a look to the full reprocudibile Rstudio project, I make it available at the end of the post.

### describing data

Linker is only able to read .csv datasets, structured as “hedge-to-hedge” tables.

This mean you will have to create a two-column table, having on each row a link.

For instance, suppose A is linked with B, C is linked with A and B is linked with D; this will be your dataset:

from to
A B
C A
B D

be sure to set ”;” as a separator in your .csv file.

using the ‘load file’ control you can choose the dataset to load.

### connecting dots

Linker leverages the great features builted in the linkComm package by Alex T. Kalinka and Alain Guenoche .

Therefore, the first step required is to create a linkComm object, containing the network map and informations about founded communities.

This object is obtained through the getLinksCommunities() function. This function takes your dataset as an input and, applying a clustering method, gives as an output the network map aggregated by community.

just note that:

• Linker use as hierarchical clustering method the mcquitty method. There are other clustering methods available. just type ?getLinkCommunities() in your console to discover them;

• the parameter use.all.edges is set to TRUE in order to show in the network all member of your networks.

### Plotting the map

as soon as Linker creates the getLinkCommunities object, it will return, in the”network map” area, a visual representation of your network.

the default graph is the spencer circle, a graph developed by Rob Spencer starting from a 2010 paper by Yong-Yeol Ahn , James P. Bagrow and Sune Lehmann .

If you prefer, you can change the graphing layout  to circle.

I think this second way is a bit more clearer, even if is not as impacting as the Spencer Circle.

#### highligthing most relevant subjects

not all the subjects in your network have got the same relevance. If you want to focus just on the most influent subjects, you can use the “number of communities” option.

This option lets you focus on subjects being part of** at least n communities**, starting from one to infinite.

##### code spec

the option uses the shownodesin argument

[code language=“r”] shownodesin = input$“n_input” [/code] #### focusing on a single community If you want to focus on a single community, you can just type the community id into the ‘community to focus on’. Community’s id are printed around the circle in the spencer circle layout. ##### code spec these option is builted using the clusterids argumenti within the plot function: [code language=“r”] clusterids = c(as.numeric(input$selected_communities)) [/code]

this is not actually a feature created within the application, but could be better described as a trick:

if you want to export your map, just right-click on the map and select “save image”.