O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

To plot the network graph, the steps are as follows:

  1. First, specify the edges for a directed graph:
> graph_directed <- graph(edges=c(1,2, 2,3, 2,4, 1,4, 5,5, 3,6, 5,6),n=6)Next specify the edges for an undirected graph using directed=FALSE parameter:> graph_undirected <- graph(edges=c(1,2, 2,3, 2,4, 1,4, 5,5, 3,6, 5,6),n=6, directed=FALSE)Now plot both the directed and undirected graph side by side:> par(mfrow=c(1,2))> plot(graph_directed)> plot(graph_undirected)
  1. Next, specify an edge list that has vertex names, and also mention the isolated list of names:
> graph_isolation <- graph( c( "Kuntal", "Maulim", "Maulim", "Yana","Yana","Kuntal", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required