Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color problems in nodes #473

Open
TimothyEbert opened this issue Jul 31, 2024 · 1 comment
Open

Color problems in nodes #473

TimothyEbert opened this issue Jul 31, 2024 · 1 comment

Comments

@TimothyEbert
Copy link

I am using RStudio running on a PC (DELL Latitude 7440) using R 4.4.1 and RStudio version 2024.4.2.764.
I am making network plots with 6 nodes.
I assign custom colors to the nodes and edges.

The problem is that some colors appear to cause problems where some edges and nodes to not appear with the right color. I check the edges data frame, and the colors are correct but an edge with one color in the data frame will print as a different color.
This graph is good:
image
If I change to "brown4" then I get this:
image

Is there a pallet that does not have problems, or what is causing this issue?

@TimothyEbert
Copy link
Author

The following is a minimally reproducible example where I have removed all of the code that converts the raw data into node and edges. I have also left out code that adjusts the physics.

library(visNetwork)

Build nodes

nodes <- data.frame(
id=c("C", "G", "NP", "D", "E1", "E2"),
label=c("C", "G", "NP", "D", "E1", "E2"),
size = c(45.095856, 37.859089, 116.437705,
1.546333, 1.373999, 23.07729),
color.background = c("cyan", "blue", "brown4",
"lightgreen", "lightgreen", "lightgreen")
)

Build edges

edges <- data.frame(
to = c('C', 'C', 'C', 'D', 'D', 'E1', 'E1',
'E2', 'E2', 'G', 'G', 'NP'),
from = c('D', 'G', 'NP', 'C', 'E1',
'C', 'E2', 'C', 'E1', 'C', 'NP', 'C'),
width = c(5.135724, 5.629823, 13.597379, 12.25, 12.4,
15.97265, 6.712251, 10, 13.333333, 19.62963, 6.666667, 20),
arrows = "to",
font_multi = "html",
color = c('lightgreen', 'blue', 'brown4', 'cyan', 'lightgreen', 'cyan',
'lightgreen', 'cyan', 'lightgreen', 'cyan', 'brown4', 'cyan')
)
visNetwork(nodes, edges)

Code where color works

Build nodes

nodes <- data.frame(
id=c("C", "G", "NP", "D", "E1", "E2"),
label=c("C", "G", "NP", "D", "E1", "E2"),
size = c(45.095856, 37.859089, 116.437705,
1.546333, 1.373999, 23.07729),
color.background = c("cyan", "blue", "brown",
"lightgreen", "lightgreen", "lightgreen")
)

Build edges

edges <- data.frame(
to = c('C', 'C', 'C', 'D', 'D', 'E1', 'E1',
'E2', 'E2', 'G', 'G', 'NP'),
from = c('D', 'G', 'NP', 'C', 'E1',
'C', 'E2', 'C', 'E1', 'C', 'NP', 'C'),
width = c(5.135724, 5.629823, 13.597379, 12.25, 12.4,
15.97265, 6.712251, 10, 13.333333, 19.62963, 6.666667, 20),
arrows = "to",
font_multi = "html",
color = c('lightgreen', 'blue', 'brown', 'cyan', 'lightgreen', 'cyan',
'lightgreen', 'cyan', 'lightgreen', 'cyan', 'brown', 'cyan')
)
visNetwork(nodes, edges)

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

No branches or pull requests

1 participant