2017-02-03

(This article was first published on Pachá (Batteries Included), and kindly contributed to R-bloggers)

On January, 10 2016 David Bowie left this earthly realm. Last month I decided to create a network and here is how to do that.

Required packages

You need jsonlite, igraph, network, plyr and R base.

Other tools

D3Plus by Alex Simoes and Dave Landry. Also Google Sheets.

My data is here.

Loading packages

Building the network

D3Plus needs three files: data, edges and nodes to visualize networks.

Data

This is the easy part. I downloaded the sheet named “data” from my spredsheet in CSV format. Then I convert the CSV to JSON with these lines:

Edges

Here is a bit trickier.

I downloaded the sheet named “collaborations” from my spredsheet in CSV format. In this matrix \(M\) this is the meaning of the entries:

$$

m_{ij} =

\begin{cases}

1 &\text{if } \text{artist } i \text{ and artist } j \text{ did collaborate to each other}\cr

0 &\text{othewise}

\end{cases}

$$

Then arrange the matrix to fix row names and column names:

With the matrix ready I can create the network. You can try different layouts explained in igraph documentation. This is the code to create the network and display a static version of it:



Now I do save the edges (names and ids) and the network layout:

Finally I rearrange the edges to display names instead of numeric ids and save the result in JSON format:

Nodes

This is easier than the edges part. The code to save the nodes in JSON format with names instead of numeric ids is:

Put your files in a D3Plus network template

In my case I decided to use bl.ocks.org to show my network. Use this template and edit the links to data, edges and nodes to make it to work.

You can also use Roboto, another Google Font or just any typography you want.

Final result

After some edges editing in Atom (just aesthetic changes to put some edges closer to similar artists) the result is here.

if (false) {
align = (screen.width

To leave a comment for the author, please follow the link and comment on their blog: Pachá (Batteries Included).

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

Show more