Building dynamic interaction graphs in Tableau using R

Student online discussion interaction data can be quite rich, it is beneficial to visualize the data in a meaningful way that helps faculty make an informed decision to engage students in online discussions. We can try a dynamic network dashboard to explore the ideas.

In previous blog, I posted a couple of online discussion interaction layouts that were generated in R with igraph package. In this blog, I would like to share another approach that uses R in Tableau to create a dynamic network graph. Please click on the image to view a video clip that shows a dynamic interaction I created in Tableau using R.animationTo build a dynamic network graph in Tableau, in addition to prepare the edge list, we need to get the x/y coordinate for each node. There are multiple way to obtain node x/y coordinate. Inspired by a blog posted by Boran Beran, in which he describes how to generate x/y coordinates in Tableau using R igraph, I decided to try the coding in Tableau to build a dynamic discussion interaction diagram.

Below includes a step-by-step instruction and sample script:

  1. Install Rserve package in R and run Rserve – Rserve(). Make sure to install igraph and plyr package in R as well.
  2. Prepare an edge list that includes the following fields: from (the interaction initiator/sender), to (the receiver), users (the field combines both from and to list), pathorder (1 for users=from, and 2 for users=to), weight (varies and depends on the elements you want to examine or the focus of a question)
  3. Import the file to Tableau
  4. Create a Tableau calculated field (GraphNodes) to generate x/y coordinates and betweenness calling R igraph:
    SCRIPT_STR(“library(igraph); library(plyr);set.seed(123);

    mydf <- data.frame(from=.arg1, to=.arg2, weight=.arg3, Order=.arg4);
    mydf <- aggregate(mydf[,3],mydf[,-3],sum);
    mydf <-mydf[(mydf$Order==’1′) & (!is.na(mydf$to)),];
    mygraph <- graph.data.frame(mydf);
    mygraph <- simplify (mygraph, remove.multiple=F, remove.loops=T);
    coords <- “+[Layout]+”(mygraph);
    c<-cbind(coords, data.frame(users=V(mygraph)$name));
    c<-cbind(c, betweenness(mygraph));
    allusers <- data.frame(users=.arg5);
    c<-join(allusers, c, by = ‘users’);
    paste(c[,2],c[,3],c[,4], sep=’~’)”,ATTR([From]), ATTR([To]),SUM([Weight]),ATTR([Pathorder]), ATTR([User]))
  5. Create calculated fields to extract x and y coordinate from the calculated field ‘GraphNodes’
    X coordinate: FLOAT(LEFT([GraphNodes],FIND([GraphNodes],’~’)-1))
    Y coordinate: FLOAT(LEFT(RIGHT([GraphNodes],LEN([GraphNodes])-FIND([GraphNodes], ‘~’)),FIND(RIGHT([GraphNodes],LEN([GraphNodes])-FIND([GraphNodes], ‘~’)),’~’)-1))
  6. Build a network diagram in Tableau: step-by-step instruction on how to build a network diagram in Tableau.

Resources about Using R in Tableau:

One thought on “Building dynamic interaction graphs in Tableau using R

  1. The portion is giving me an error. With this syntax, my calculated field cannot be validated. I modified the code to be and was able to validate my calculated field and build my X Coordinates and Y Coordinates fields as well.

    However, when I drag my X Cooridnates to the Columns shelf, I recieve the following error: .

Leave a Reply

Your email address will not be published. Required fields are marked *