Both the nodes and edges data sets can contain some extra columns which can be used in the network graph. For example, in the nodes data set I have used restaurant type (French, Chinese, Indian,…) to color my nodes. And in the edges data set I have specified the strength of the edge/link. In my case I have defined the strength as the number of reviewers. So, If reviewer x, y and z have reviewed restaurants A and B then the strength of edge A-B is 3.
Before I went to the university I have lived in the lovely city of of Hoorn in the Netherlands. Lets look at the restaurants in Hoorn and how they are connected. The restaurant nodes data set looks like:
The restaurant edges data set looks like:
Given the two data sets, the R code to create the network is given by
visNetwork( RestaurantNodes, RestaurantEdges, legend = TRUE) %>% visOptions( highlightNearest = TRUE, nodesIdSelection = TRUE) %>% visInteraction( navigationButtons = TRUE) %>% visPhysics( maxVelocity = 35)
There are many options you can set, see the help for more information. I have just used a couple. A handy option is highlightNearest, when there are many nodes you can select a node and only the nodes nearest to the selected are highlighted and the rest is grayed out. Here are some screen shots of my network graph, click to enlarge.
Don’t they look lovely? In the interactive graph the nodes can ‘vibrate’, just like atomic nuclei. I have published the network graph on Rpubs so that you can interact with the graph yourself. Apart from the nostalgic reason to choose restaurants in Hoorn, there is another reason, when there are too many nodes and edges the graph does not perform well. Trying to create this graph for all restaurants in the Netherlands is not possible.