1 Reply Latest reply on Feb 13, 2019 3:06 PM by Andres Garcia

    R + Network Analysis

    Joana Neto

      Hi,

       

      I'm trying to adapt this Building dynamic interaction graphs in Tableau using R | Analytics in Instructional Design  to my own script:

       

       

      SCRIPT_STR("library(igraph); library(plyr);set.seed(123);

      mydf <- data.frame(from=.arg1, to=.arg2, weight=.arg3, Order=.arg4);

      mydf <-mydf[(mydf$Order=='1') & (!is.na(mydf$to))];

      mygraph <- graph.data.frame(mydf, directed=F);

      coords <- "+[Layout]+"(mygraph, weights=E(mygraph)$weight);

      c<-cbind(coords, data.frame(Acct_Num=V(mygraph)$name));

      c<-cbind(c, betweenness(mygraph));

      allusers <- data.frame(Mer_Name=.arg5);

      c<-join(allusers, c, by = 'Acct Num');

      paste(c[,2],c[,3],c[,4], sep='~')",ATTR([Acct Num]), ATTR([Terminal
      Id]),SUM([Number of Records]),ATTR([Relationship Mer AccN]), ATTR([Mer Name]))

       

      However, I'm getting the following error message:

       

      "An error occurred while communicating with the RServe service. Error in graph.data.frame(mydf, directed = F) : the data frame should contain at least two columns"

       

      I'm a newbie in R and Tableau so it might be something there that I'm missing. In the data source I've linked to my book I've more than 2 columns, so not sure what to do.

       

      Thanks in advance for any help.

       

        • 1. Re: R + Network Analysis
          Andres Garcia

          Hi! can you share your workbook please

           

          Can you use this code instead

          SCRIPT_STR("library(igraph); library(plyr);set.seed(123);

          mydf <- data.frame(from=.arg1, to=.arg2, weight=.arg3, Order=.arg4);

          mydf <-mydf[(!is.na(mydf$to))];

          mygraph <- graph.data.frame(mydf, directed=F);

          coords <- "+[Layout]+"(mygraph, weights=E(mygraph)$weight);

          c<-cbind(coords, data.frame(Acct_Num=V(mygraph)$name));

          c<-cbind(c, betweenness(mygraph));

          allusers <- data.frame(Acct_Num=.arg5);

          c<-join(allusers, c, by = 'Acct_Num');

          paste(c[,2],c[,3],c[,4], sep='~')",ATTR([Acct Num]), ATTR([Terminal
          Id]),SUM([Number of Records]),ATTR([Relationship Mer AccN]), ATTR([Mer Name]))

           

          Thanks!

           

          Andres FG