Reboot of rgexf

November 7, 2017
By

(This article was first published on Posts on GGVY, and kindly contributed to R-bloggers)

The rgexf R package has been around a couple of years now, but without much going on on CRAN (my bad!). In this post I’ll show how to use the new version (on development and soon the be shipped to CRAN) together with the netdiffuseR R package to visualize a random diffusion process.

First, we load all the packages that we will be using

# Loading the relevant packages
library(igraph, quietly = TRUE)
library(rgexf, quietly = TRUE)
library(netdiffuseR, quietly = TRUE)

Next, we simulate a random diffusion network, in this case, a small-world network with 200 nodes spanning 20 time periods.

# A random diffusion network
set.seed(122)
net <- rdiffnet(n = 200, t=20, seed.graph = "small-world")

Now, we get the parameters ready, in this case, position using the function layout_nicely from the igraph package, and colors using the Time of Adoption (toa)

# Setting viz attributes
pos <- cbind(layout_nicely(diffnet_to_igraph(net)[[1]]), 0)

# Coloring according to time of adoption. White ones are not
# adopters.
col <- diffnet.toa(net)
col <- col/20
col <- colorRamp(blues9, alpha = TRUE)(col)
col[is.na(col[,1]),1:3] <- 255
col[,4] <- .5

Finally, we create the GEXF object and call the plot function. In this case we are using gexf-js (sigma-js will return in the future). Also, notice that we are only copying the files; the default behavior is to copy the files by setting copy.only = TRUE and start the server using the servr.

# Creating the gexf object
gf <- igraph.to.gexf(
  diffnet_to_igraph(net)[[1]],
  nodesVizAtt = list(
    color    = col,
    position = pos
    )
  )

# Plotting using gexf-js
plot(
  gf,
  edgeWidthFactor = .1,
  copy.only = TRUE,
  dir       = "../../static/post/reboot-of-rgexf/viz"
  )
## GEXF graph successfully written at:
## /home/george/Documents/website/static/post/reboot-of-rgexf/viz/network.gexf

You can take a look at resulting website here.

Session info

devtools::session_info()
## Session info -------------------------------------------------------------
##  setting  value                       
##  version  R version 3.4.4 (2018-03-15)
##  system   x86_64, linux-gnu           
##  ui       X11                         
##  language en_US                       
##  collate  en_US.UTF-8                 
##  tz       America/Los_Angeles         
##  date     2018-06-18
## Packages -----------------------------------------------------------------
##  package        * version   date       source        
##  backports        1.1.2     2017-12-13 cran (@1.1.2) 
##  base           * 3.4.4     2018-03-16 local         
##  blogdown         0.6       2018-04-18 CRAN (R 3.4.4)
##  bookdown         0.7       2018-02-18 CRAN (R 3.4.3)
##  boot             1.3-20    2017-07-30 CRAN (R 3.4.1)
##  coda             0.19-1    2016-12-08 CRAN (R 3.4.0)
##  codetools        0.2-15    2016-10-05 CRAN (R 3.3.1)
##  colorspace       1.3-2     2016-12-14 CRAN (R 3.4.0)
##  compiler         3.4.4     2018-03-16 local         
##  datasets       * 3.4.4     2018-03-16 local         
##  devtools         1.13.5    2018-02-18 CRAN (R 3.4.3)
##  digest           0.6.15    2018-01-28 cran (@0.6.15)
##  evaluate         0.10.1    2017-06-24 CRAN (R 3.4.0)
##  ggplot2          2.2.1     2016-12-30 CRAN (R 3.4.3)
##  graphics       * 3.4.4     2018-03-16 local         
##  grDevices      * 3.4.4     2018-03-16 local         
##  grid             3.4.4     2018-03-16 local         
##  gridExtra        2.3       2017-09-09 CRAN (R 3.4.4)
##  gtable           0.2.0     2016-02-26 CRAN (R 3.4.0)
##  htmltools        0.3.6     2017-04-28 CRAN (R 3.4.0)
##  httpuv           1.4.3     2018-05-10 CRAN (R 3.4.4)
##  igraph         * 1.2.1     2018-03-10 CRAN (R 3.4.3)
##  knitr            1.20      2018-02-20 CRAN (R 3.4.3)
##  later            0.7.3     2018-06-08 CRAN (R 3.4.4)
##  lattice          0.20-35   2017-03-25 CRAN (R 3.3.3)
##  lazyeval         0.2.1     2017-10-29 CRAN (R 3.4.2)
##  magrittr         1.5       2014-11-22 CRAN (R 3.4.0)
##  MASS             7.3-50    2018-04-30 CRAN (R 3.4.4)
##  MatchIt          3.0.2     2018-01-09 CRAN (R 3.4.3)
##  Matrix           1.2-14    2018-04-09 CRAN (R 3.4.4)
##  memoise          1.1.0     2017-04-21 CRAN (R 3.4.0)
##  methods        * 3.4.4     2018-03-16 local         
##  munsell          0.5.0     2018-06-12 CRAN (R 3.4.4)
##  netdiffuseR    * 1.20.0    2018-06-07 CRAN (R 3.4.4)
##  network          1.13.0.1  2018-04-02 CRAN (R 3.4.4)
##  networkDynamic   0.9.0     2016-01-15 CRAN (R 3.4.0)
##  pillar           1.2.3     2018-05-25 CRAN (R 3.4.4)
##  pkgconfig        2.0.1     2017-03-21 CRAN (R 3.4.0)
##  plyr             1.8.4     2016-06-08 CRAN (R 3.4.0)
##  promises         1.0.1     2018-04-13 CRAN (R 3.4.4)
##  R6               2.2.2     2017-06-17 CRAN (R 3.4.4)
##  Rcpp             0.12.17   2018-05-18 CRAN (R 3.4.4)
##  rgexf          * 0.16.0    2018-02-05 local         
##  rlang            0.2.1     2018-05-30 CRAN (R 3.4.4)
##  rmarkdown        1.10      2018-06-11 CRAN (R 3.4.4)
##  rprojroot        1.3-2     2018-01-03 cran (@1.3-2) 
##  scales           0.5.0     2017-08-24 CRAN (R 3.4.1)
##  servr            0.10      2018-05-30 CRAN (R 3.4.4)
##  sna              2.4       2016-08-08 CRAN (R 3.4.0)
##  SparseM          1.77      2017-04-23 CRAN (R 3.4.0)
##  statnet.common   4.1.2     2018-06-05 CRAN (R 3.4.4)
##  stats          * 3.4.4     2018-03-16 local         
##  stringi          1.2.3     2018-06-12 CRAN (R 3.4.4)
##  stringr          1.3.1     2018-05-10 CRAN (R 3.4.4)
##  tibble           1.4.2     2018-01-22 cran (@1.4.2) 
##  tools            3.4.4     2018-03-16 local         
##  utils          * 3.4.4     2018-03-16 local         
##  viridis          0.5.1     2018-03-29 CRAN (R 3.4.3)
##  viridisLite      0.3.0     2018-02-01 cran (@0.3.0) 
##  withr            2.1.2     2018-03-15 cran (@2.1.2) 
##  xfun             0.2       2018-06-16 CRAN (R 3.4.4)
##  XML              3.98-1.11 2018-04-16 CRAN (R 3.4.4)
##  yaml             2.1.19    2018-05-01 CRAN (R 3.4.4)

Last updated

This post was last updated on 2017-11-13 to reflect a small change in rgexf that makes it easier to process colors and positions.

To leave a comment for the author, please follow the link and comment on their blog: Posts on GGVY.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)