# Network Analysis using R

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!

• 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 Sep 7 '16 at 14:01
• 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 Sep 7 '16 at 14:04
• 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 cran.r-project.org/web/packages/igraph/igraph.pdf – DaveRGP Sep 8 '16 at 14:43
• The other part to this is you need to specify your edges, i.e. where the joins are. – DaveRGP Sep 8 '16 at 14:56

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.

• 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 Sep 13 '16 at 14:08
• Sure, 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 Sep 13 '16 at 14:54