Skip to content

Conversation

@aj2duncan
Copy link
Contributor

What my pull improves (if applicable)

#21

This is just something I would like to be able to do directly, rather than having to use the metric calculations with sizeVector(). I completely understand if it isn't a functionality that you interested in.

Confirmation that you have tested your code

The code below demonstrates that the updated function produces the same results as direct calculation.

# testing directed networks
library(sigmaNet)
library(igraph)
library(magrittr)

set.seed(42)
g <- sample_gnm(25, 50, directed = TRUE)
V(g)$label = LETTERS[1:25] # adding labels
layout <- layout_with_kk(g)
sig <- sigmaFromIgraph(g, layout = layout)

# test the defaults match the expected results
sig_graph1a <- sig %>%
  addNodeSize(minSize = 1, maxSize = 8)
sig_graph1b <- sig %>%
  addNodeSize(sizeMetric = "closeness", minSize = 1, maxSize = 8)
# same but using igraph to calculate values directly
sig_graph2a <- sig %>%
  addNodeSize(sizeVector = degree(g), minSize = 1, maxSize = 8)
sig_graph2b <- sig %>%
  addNodeSize(sizeVector = closeness(g), minSize = 1, maxSize = 8)
# test identical
identical(jsonlite::fromJSON(sig_graph1a$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2a$x$data)$nodes$size)
identical(jsonlite::fromJSON(sig_graph1b$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2b$x$data)$nodes$size)

# repeat for different types
# test the defaults match the expected results
sig_graph1a <- sig %>%
  addNodeSize(sizeMetric = "degree", mode = "in", minSize = 1, maxSize = 8)
sig_graph1b <- sig %>%
  addNodeSize(sizeMetric = "closeness", mode = "in", minSize = 1, maxSize = 8)
# same but using igraph to calculate values directly
sig_graph2a <- sig %>%
  addNodeSize(sizeVector = degree(g, mode = "in"), minSize = 1, maxSize = 8)
sig_graph2b <- sig %>%
  addNodeSize(sizeVector = closeness(g, mode = "in"), minSize = 1, maxSize = 8)
# test identical
identical(jsonlite::fromJSON(sig_graph1a$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2a$x$data)$nodes$size)
identical(jsonlite::fromJSON(sig_graph1b$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2b$x$data)$nodes$size)

# final possible types
# test the defaults match the expected results
sig_graph1a <- sig %>%
  addNodeSize(sizeMetric = "degree", mode = "out", minSize = 1, maxSize = 8)
sig_graph1b <- sig %>%
  addNodeSize(sizeMetric = "closeness", mode = "all", minSize = 1, maxSize = 8)
# same but using igraph to calculate values directly
sig_graph2a <- sig %>%
  addNodeSize(sizeVector = degree(g, mode = "out"), minSize = 1, maxSize = 8)
sig_graph2b <- sig %>%
  addNodeSize(sizeVector = closeness(g, mode = "all"), minSize = 1, maxSize = 8)
# test identical
identical(jsonlite::fromJSON(sig_graph1a$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2a$x$data)$nodes$size)
identical(jsonlite::fromJSON(sig_graph1b$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2b$x$data)$nodes$size)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants