Network Analysis using R

0

I've the following dataset:

**Strenght  Movie1  Movie2** 
  23            2        3 
  80            1        2  
  10            4        3 

And I want to create a graph with the relationships between movies having the first column as the strenght of the relationship. How can I do this using R?

Many thanks!

João_testeSW

Posted 2016-09-07T12:56:32.213

Reputation: 159

There are several ways how graphs can be represented. Which representation you need depends on what you're planning to do with the graph / what algorithms you want to run on it. – stmax – 2016-09-07T14:01:16.633

I'm tryig to build a graph that shows the relationships of the movies having the first column as the strenght of the relationships. Like the graphs created in Gephi. Which algorithm I need to use? – João_testeSW – 2016-09-07T14:04:05.917

Algorithm may be the wrong word. If you want a graph that demonstrates distance in a network graph as the values in the first column try the igraph package on CRAN https://cran.r-project.org/web/packages/igraph/igraph.pdf

– DaveRGP – 2016-09-08T14:43:57.847

The other part to this is you need to specify your edges, i.e. where the joins are. – DaveRGP – 2016-09-08T14:56:41.483

Answers

2

Try this R code:

library(igraph)
dfr <- data.frame(idMovie1=c(2,1,4), idMovie2=c(3, 2, 3), strength=c(23,80,10))

igr <- igraph::graph.data.frame(dfr)
plot(x = igr,
     edge.curved=FALSE, edge.width=log(edge_attr(igr)$strength), edge.label=edge_attr(igr)$strength,
     main="Graph of Movie Strengths")

Works only for small daasets. visualizations get ugly quickly.

igraph

knb

Posted 2016-09-07T12:56:32.213

Reputation: 535

Sorry mu ignorance but is possible to make the dataframe: dfr <- data.frame(idMovie1=c(2,1,4), idMovie2=c(3, 2, 3), strength=c(23,80,10))

reading directly from my txt file? – João_testeSW – 2016-09-13T14:08:15.280

1Sure, but that is basic R. Use the read.csv() function or one of its variants. You might have to reorder the columns, remove duplicates, impute NAs.... standard stuff. – knb – 2016-09-13T14:54:15.220