R visNetwork: how to set labels bold and increase margins around labels
Asked Answered
U

1

6

I created a network graph using the visNetwork package (I have little knowledge of other languages, sorry).

I want two points (Please look at the left below image)

  1. To make labels bold.
  2. To increase space between labels and border.

Can I do them with R?

Any help would be greatly appreciated. Below is an example code and the outputs:

library(dplyr); library(visNetwork)

visNetwork(nodes = data_frame(id = 1:3, 
                              label = c("abcdef", "xxx", "y"),
                              shape = "box"),
           edges = data_frame(from = c(1, 1, 2),
                              to = c(2, 3, 3),
                              arrows = "to")) %>% 
  visNodes(font = list(size = 17),
           color = list(background = "aliceblue", border = "darkblue")) %>% 
  visEdges(width = 2) %>% 
  visIgraphLayout(layout = "layout_nicely")

enter image description hereenter image description here

Umiak answered 21/11, 2018 at 1:37 Comment(0)
B
0

My first ever post on StackOverflow. Found this solution by searching for non-R (i.e. Vis.js) solutions and a bit of tweaking to make it work in R. Vis.js - set graph label's font as bold

Step 1: Wrap your labels in HTML code, <b></b> in this case because you want them bold. E.g. mutate(label = paste0("<b>", label, "</b>"))

Step 2: Enable displaying html elements in the label by including multi = "html" in visNodes().

Below code will make your labels bold:

library(dplyr); library(visNetwork)

visNetwork(nodes = data_frame(id = 1:3, 
                              label = c("<b>abcdef</b>", "<b>xxx</b>", "<b>y</b>"),
                              shape = "box"),
           edges = data_frame(from = c(1, 1, 2),
                              to = c(2, 3, 3),
                              arrows = "to")) %>% 
  visNodes(font = list(size = 17, multi = "html"),
           color = list(background = "aliceblue", border = "darkblue")) %>% 
  visEdges(width = 2) %>% 
  visIgraphLayout(layout = "layout_nicely")
Blenheim answered 14/11, 2023 at 23:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.