Once you know how to make a basic network graph and how to custom the colors of its nodes, you probably want to map the colors following the value of an external variable.

Here we consider a network with 10 people. Each is either adult, old or young and we want one specific color for each category.

On the left you have the default chart with no color.


Map a color



The dataset is composed by 2 data frames. ‘Links’ gives the links between people. ‘Nodes’ gives features concerning people. What we need is to transform the “carac” column into a vector of 3 colors, and provide this vector to the plot. The 3 colors are picked up in an Rcolorbrewer palette as described in graph #39.


Modify Vertex Labels



Not that we can easily map other variables to other parameters, following the same protocol. Here is an example where we map the importance of the nodes to the edge width. (There is an ‘importance’ column in the ‘links’ data frame)



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


Leave a Reply

Notify of