0
$\begingroup$

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!

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – stmax Sep 7 '16 at 14:01
  • $\begingroup$ 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? $\endgroup$ – João_testeSW Sep 7 '16 at 14:04
  • $\begingroup$ 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 $\endgroup$ – DaveRGP Sep 8 '16 at 14:43
  • $\begingroup$ The other part to this is you need to specify your edges, i.e. where the joins are. $\endgroup$ – DaveRGP Sep 8 '16 at 14:56
2
$\begingroup$

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

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – João_testeSW Sep 13 '16 at 14:08
  • 1
    $\begingroup$ 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. $\endgroup$ – knb Sep 13 '16 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.