diff --git a/DESCRIPTION b/DESCRIPTION index c6bf9e9..ad758b3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: sigmaNet Title: Render Graphs Using 'Sigma.js' -Version: 1.1.0 +Version: 1.2.0 Authors@R: person("Ian", "Kloo", email = "iankloo@gmail.com", role = c("aut", "cre")) Maintainer: Ian Kloo URL: https://github.com/iankloo/sigmaNet diff --git a/R/sigmaAttrs.R b/R/sigmaAttrs.R index 8592ebb..17ed0c7 100644 --- a/R/sigmaAttrs.R +++ b/R/sigmaAttrs.R @@ -59,7 +59,7 @@ addNodeColors <- function(sigmaObj, oneColor = NULL, colorAttr = NULL, colorPal graphOut <- list(nodes, edges, directed) names(graphOut) <- c('nodes','edges', 'directed') - + sigmaObj$x$data <- jsonlite::toJSON(graphOut, pretty = TRUE) return(sigmaObj) } @@ -76,6 +76,7 @@ addNodeColors <- function(sigmaObj, oneColor = NULL, colorAttr = NULL, colorPal #' @param minSize The minimum node size on the graph (for scaling) #' @param maxSize The maximum node size on the graph (for scaling) #' @param sizeMetric The metric to use when sizing the nodes. Options are: degree, closeness, betweenness, pageRank, or eigenCentrality. +#' @param mode The mode to be used when calculating degree or closeness for directed networks. Options are: all, in, out and total. The default behaviour will match that of igraph. #' @param sizeVector An optional vector with the sizes for each node (overrides sizeMetric and min/maxSize) #' @param oneSize A single size to use for all nodes #' @@ -108,11 +109,11 @@ addNodeColors <- function(sigmaObj, oneColor = NULL, colorAttr = NULL, colorPal #' sig #' #' @export -addNodeSize <- function(sigmaObj, minSize = 1, maxSize = 3, sizeMetric = 'degree', sizeVector = NULL, oneSize = NULL){ +addNodeSize <- function(sigmaObj, minSize = 1, maxSize = 3, sizeMetric = 'degree', mode = NULL, sizeVector = NULL, oneSize = NULL){ edges <- jsonlite::fromJSON(sigmaObj$x$data)$edges nodes <- jsonlite::fromJSON(sigmaObj$x$data)$nodes directed <- jsonlite::fromJSON(sigmaObj$x$data)$directed - + if(!is.null(oneSize)){ nodes$size <- oneSize sigmaObj$x$options$minNodeSize <- oneSize @@ -125,10 +126,19 @@ addNodeSize <- function(sigmaObj, minSize = 1, maxSize = 3, sizeMetric = 'degree tmp_graph <- igraph::graph_from_data_frame(d = edges, directed = directed, vertices = nodes$id) + # set default mode to match those of igraph + if(is.null(mode)){ + if(sizeMetric == 'degree'){ + mode = "all" + } else if(sizeMetric == 'closeness'){ + mode = "out" + } + } + if(sizeMetric == 'degree'){ - nodes$size <- igraph::degree(tmp_graph) + nodes$size <- igraph::degree(tmp_graph, mode = mode) } else if(sizeMetric == 'closeness'){ - nodes$size <- igraph::closeness(tmp_graph) + nodes$size <- igraph::closeness(tmp_graph, mode = mode) } else if(sizeMetric == 'betweenness'){ nodes$size <- igraph::betweenness(tmp_graph, directed = directed) } else if(sizeMetric == 'pageRank'){ @@ -144,7 +154,7 @@ addNodeSize <- function(sigmaObj, minSize = 1, maxSize = 3, sizeMetric = 'degree graphOut <- list(nodes, edges, directed) names(graphOut) <- c('nodes','edges', 'directed') - + sigmaObj$x$data <- jsonlite::toJSON(graphOut, pretty = TRUE) return(sigmaObj) @@ -242,7 +252,7 @@ addEdgeSize <- function(sigmaObj, sizeAttr = NULL, minSize = 1, maxSize = 5, one graphOut <- list(nodes, edges, directed) names(graphOut) <- c('nodes','edges', 'directed') - + sigmaObj$x$data <- jsonlite::toJSON(graphOut, pretty = TRUE) return(sigmaObj) } @@ -299,7 +309,7 @@ addEdgeColors <- function(sigmaObj, oneColor = NULL, colorAttr = NULL, colorPal graphOut <- list(nodes, edges, directed) names(graphOut) <- c('nodes','edges', 'directed') - + sigmaObj$x$data <- jsonlite::toJSON(graphOut, pretty = TRUE) return(sigmaObj) } @@ -307,7 +317,7 @@ addEdgeColors <- function(sigmaObj, oneColor = NULL, colorAttr = NULL, colorPal #' #' Add edge arrows to a directed graph. Due to complexities of writing custom renderers in webGL, we are stuck with one #' arrow:edge size ratio. In other words, you can only affect the edge arrow size by making the edges bigger. -#' +#' #' This is only applicable for directed graphs - if you run this on an undirected graph, you'll get an error. #' #' @param sigmaObj A 'sigmaNet' object - created using the 'sigmaFromIgraph' function diff --git a/docs/CODE_OF_CONDUCT.html b/docs/CODE_OF_CONDUCT.html index ab662c0..a7a98cc 100644 --- a/docs/CODE_OF_CONDUCT.html +++ b/docs/CODE_OF_CONDUCT.html @@ -58,7 +58,7 @@ sigmaNet - 1.1.0 + 1.2.0 diff --git a/docs/CONTRIBUTING.html b/docs/CONTRIBUTING.html index a7d3e69..01c3591 100644 --- a/docs/CONTRIBUTING.html +++ b/docs/CONTRIBUTING.html @@ -58,7 +58,7 @@ sigmaNet - 1.1.0 + 1.2.0 diff --git a/docs/ISSUE_TEMPLATE.html b/docs/ISSUE_TEMPLATE.html index 82635fe..bb88046 100644 --- a/docs/ISSUE_TEMPLATE.html +++ b/docs/ISSUE_TEMPLATE.html @@ -58,7 +58,7 @@ sigmaNet - 1.1.0 + 1.2.0 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 5282b0c..c65bf0d 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -58,7 +58,7 @@ sigmaNet - 1.1.0 + 1.2.0 diff --git a/docs/PULL_REQUEST_TEMPLATE.html b/docs/PULL_REQUEST_TEMPLATE.html index 5c7f1fd..25976d4 100644 --- a/docs/PULL_REQUEST_TEMPLATE.html +++ b/docs/PULL_REQUEST_TEMPLATE.html @@ -58,7 +58,7 @@ sigmaNet - 1.1.0 + 1.2.0 diff --git a/docs/articles/getting-started.html b/docs/articles/getting-started.html index 15e9e98..5f39511 100644 --- a/docs/articles/getting-started.html +++ b/docs/articles/getting-started.html @@ -29,7 +29,7 @@ sigmaNet - 1.1.0 + 1.2.0 @@ -144,621 +144,621 @@

sig <- sigmaFromIgraph(lesMis, l)

Now, let’s render the basic visualization:

sig
-
-

Now, we can modify the visualization using the ‘magrittr’ pipe. First, let’s resize the nodes based on degree:

sig %>%
   addNodeSize(sizeMetric = 'degree', maxSize = 8)
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
-

R Markdown

-

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

-

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

-
summary(cars)
-
##      speed           dist       
-##  Min.   : 4.0   Min.   :  2.00  
-##  1st Qu.:12.0   1st Qu.: 26.00  
-##  Median :15.0   Median : 36.00  
-##  Mean   :15.4   Mean   : 42.98  
-##  3rd Qu.:19.0   3rd Qu.: 56.00  
-##  Max.   :25.0   Max.   :120.00
-
-
-

Including Plots

-

You can also embed plots, for example:

-

-

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

-
- - -
-
- The views expressed in this post are solely those of the author(s) and do not necessarily reflect the official policy or position of the U.S. Army, the Department of Defense, or any other agency of the U.S. government. -
-
- - - -
- - - - - - - -