Creating Network graphs using multiple nodes



Hi Team,

I would like to know how to create network graph using python or R when data is available in given format (You can see the format in attached file) (6.4 KB)


Hi @Surya1987 we can use igraph package in R to plot network data. However, you will have to reshape your input data a bit. You may refer the code below


# reading sample data
mydata = read.csv("data_network.csv")

Now we will split the input data into 2 dataframes.

In the first dataframe, the first two columns are the IDs of the source and the target node for each edge. The second dataframe consists of node IDs.

# reshaping the sample data
d = data.frame(source = c(1,1,1,2,2,2,3,3,4,4,5,5,6,6),
               target = c(2,3,4,3,4,5,6,7,6,2,3,6,2,7))

vertices = data.frame(v = c(1:7))

Finally ploting the network.

net = graph_from_data_frame(d=d, vertices=vertices, directed=T) 

plot(net, edge.arrow.size=.4)



Thank you