I am working with the R programming language.
I have the following graph network :
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)
edges <- data.frame(from = sample(1:20, 100, replace = TRUE), to = sample(1:20, 100, replace = TRUE))
nodes$shape <- 'circle'
edges$weight <- apply(edges, 1, function(x) mat[x["from"], x["to"]])
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 Now, I want to add "edge labels" to this network (based on the weight column):
from to weight
1 6 11 0.061566284
2 10 12 0.078716949
3 10 8 0.001003639
4 6 18 0.044656020
5 16 5 0.061479305
6 16 18 0.060615245
I found this link here and have been trying to adapt the code from here to add the labels : Edges
But I am having trouble doing this - I tried the following code but no labels appear:
network <- visNetwork(nodes, edges) %>%
visEdges(arrows = list(to = list(enabled = TRUE)), label = list(enabled = TRUE)) %>%
visIgraphLayout(layout = "layout_in_circle")
network
Can someone please show me how to fix this?
Thanks!