How to change colour of selected node or edge when using the visNetwork package in R?

Electrino

A similar question has been asked here, but I cant seem to adapt it to my code. What I'm trying to do is change the colour of the nodes and edges using the visNetwork package in R. I want to apply this colour change when either

1: the mouse is hovering over a node/edge and

2: when a node or edge is clicked on.

Below is some code to create a very simple network.

# Load required packages
library(visNetwork)

# Create example data
nodes <- data.frame(id = 1:3, label = c("Node 1", "Node 2", "Node 3"))
edges <- data.frame(from = c(1, 1, 2), to = c(2, 3, 3), value = c(10, 20, 30))

# Create visNetwork object with customized node and edge colors
visNetwork(nodes, edges) |>  
  visNodes(color = list(background = "red", 
           border = "black")) |> 
  visEdges(color = "blue", smooth = FALSE)|>
  visOptions(highlightNearest = list(enabled = T, hover = T),
                                    nodesIdSelection = T)

At the moment, I have the nodes coloured red and when hovering over/clicking the node with the mouse, it automatically changes colour to a blue. I would like to control that colour somehow. Also, when selecting an edge, it just seems to make the edge thicker but keeps the same colour. I want to try and change the edge colour when selecting it.

I have tried playing with the visOptions, visEdges, and visNodes arguments, but I just can't seem to figure it out.

bretauv

From ?visEdges (or ?visNodes), argument color:

Named list or String. Default to named list. Color information of the edge in every situation. Can be 'rgba(120,32,14,1)', '#97C2FC' (hexa notation on 7 char without transparency) or 'red'.

  • "color" : String. Default to '#848484. The color of the edge when it is not selected or hovered over (assuming hover is enabled in the interaction module).
  • "highlight " : String. Default to '#848484'. The color the edge when it is selected.
  • "hover" : String. Default to '#848484'. The color the edge when the mouse hovers over it (assuming hover is enabled in the interaction module).
  • ...
# Load required packages
library(visNetwork)

# Create example data
nodes <- data.frame(id = 1:3, label = c("Node 1", "Node 2", "Node 3"))
edges <- data.frame(from = c(1, 1, 2), to = c(2, 3, 3), value = c(10, 20, 30))

# Create visNetwork object with customized node and edge colors
visNetwork(nodes, edges) |>  
  visNodes(color = list(background = "red", border = "black", highlight = "yellow",
                        hover = "yellow")) |> 
  visEdges(color = list(color = "blue", highlight = "yellow", 
                        hover = "yellow"), smooth = FALSE)|>
  visOptions(highlightNearest = list(enabled = T, hover = T),
             nodesIdSelection = T)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to change AppBar colour when another tab is selected using ChangeNotifierProvider on Flutter?

Preventing change in colour and background colour of selected option when blurred

r visNetwork node position issue

How to specify nodes' positions in visNetwork package in R

How to change the foreground or background colour of a selected cell in tkinter treeview?

R Markdown: visNetWork not displayed in html output when using for loops (or functions)

how to change the colour of a cardview when selected?clicked

How to change the colour of a button when clicked on? (Vue)

WPF : How to change the MouseOver/Selected background colour of a GridView row

How to show the node's label when selected them in VisNetwork?

Change the colour of the buttons of the toolbar when using Quill?

How to change the colour of JTextArea when it is not editable?

How would i change a <div> border colour when a drop down box is selected

How to change colour of selected cell in UITableView?

how to change collection view cell background colour when it is selected?

How to make a colour change on click, to load with one button selected

why doesn't this visNetwork in R show edge

How to programmatically change selected tabItem Header colour from code behind

R visNetwork shiny: change color of selected node

Change Vertex Node colour for specific edge igraph R

In Eclipse, how to change the colour of the selected console text's highlighting colour?

Change background and label colour of UICollectionView cell when it is selected

How to change the symbol and colour using fviz_cluster in R project

How to change the colour of selected button when clicked using target method?

How to change colour of selected icon in the BottomNavigation component of React Native Paper?

How to change button colour when active on React

Power BI Change SLICER background colour when selected

How to change colour for barplot in ggplot2 using viridis package?

How to show colour change when customised radio button is selected?