I am working with the R programming language.
In a previous question (R: Adding Labels From Matrix to a Graph), I learned how to make the following network graph:
library(tidyverse)
library(visNetwork)
library(htmlwidgets)
set.seed(123)
mat <- matrix(runif(19*20), nrow = 19, ncol = 20)
mat <- t(apply(mat, 1, function(x) x/sum(x)))
mat <- rbind(mat, c(rep(0, 19), 1))
nodes <- data.frame(id = 1:20,
label = paste("Node", 1:20))
edges <- data.frame(from = sample(1:20, 100, replace = TRUE),
to = sample(1:20, 100, replace = TRUE),
label = paste("Edge", 1:100))
nodes$shape <- 'circle'
# create the network graph
network <- visNetwork(nodes, edges) %>%
visEdges(arrows = list(to = list(enabled = TRUE))) %>%
visIgraphLayout(layout = "layout_in_circle")
network
My Question: I am trying to understand how this command works list(to = list(enabled = TRUE))
For example, suppose I make the following modification:
set.seed(123)
mat <- matrix(runif(19*20), nrow = 19, ncol = 20)
mat <- t(apply(mat, 1, function(x) x/sum(x)))
mat <- rbind(mat, c(rep(0, 19), 1))
nodes <- data.frame(id = 1:20,
label = paste("Node", 1:20))
edges <- data.frame(from = sample(1:20, 100, replace = TRUE),
to = sample(1:20, 100, replace = TRUE))
edges$label <- apply(edges, 1, function(x) mat[x["from"], x["to"]])
network <- visNetwork(nodes, edges) %>%
visEdges(arrows = list(to = list(enabled = TRUE))) %>%
visIgraphLayout(layout = "layout_in_circle")
Suddenly I lose the edge labels on the graph?
Can someone please help me understand how the list(to = list(enabled = TRUE))
statement works and why the modification I made makes me lose the edge labels? Is there a way to prevent this from happening?
Thanks!