Open DanielIAvila opened 5 months ago
No need to turn the colours to a factor. You can use the I()
function to use the colour that is explicitely saved as an attribute
library(ggraph)
library(igraph)
g <- make_graph("zachary")
E(g)$colour <- "red"
E(g)$colour[incident(g, 1)] <- "blue"
layout_matrix <- graphlayouts::layout_with_stress(g)
V(g)$size <- degree(g)
V(g)$color <- as.character(membership(cluster_louvain(g)))
#not working
ggraph(g, layout = layout_matrix) +
geom_edge_link(aes(edge_colour = factor(E(g)$colour), colour = factor(E(g)$colour)), show.legend = FALSE) +
geom_node_point(aes(size = size, colour = color), show.legend = FALSE)
#working
ggraph(g, layout = layout_matrix) +
geom_edge_link(aes(edge_colour = I(E(g)$colour), colour = I(E(g)$colour)), show.legend = FALSE) +
geom_node_point(aes(size = size, colour = color), show.legend = FALSE)
Created on 2024-05-30 with reprex v2.1.0
I am experiencing this exact same issue. In my graph I have specified a color under E(g)$color that I want to use, and it is not working. It is taking the default colors used in ggplot2.
I have tried both the combination and stand-alone version of what is described here and it is not working. I have tried it for the nodes, and it is not working either. The graph
g
has attributesV(g)$year, V(g)$type, V(g)$size, V(g)$color, E(g)$color
.I need to color the nodes and the edges according to the specified attributes.
Below my R session: