Closed aosavi closed 10 months ago
@aosavi If you haven't found a solution yet (or anyone having this problem too):
You need to use edge_alpha
in override.aes instead of alpha
library(ggraph)
library(igraph)
g <- sample_gnp(20, 0.2)
E(g)$weight <- sample(1:34, ecount(g), replace = TRUE)
V(g)$grp <- sample(LETTERS[1:5], vcount(g), replace = TRUE)
V(g)$id <- 1:vcount(g)
ggraph(g, layout = "stress") +
geom_edge_link(aes(edge_color = weight), edge_width = 4, edge_alpha = 0.2) +
geom_node_point(aes(color = grp), alpha = 0.2, size = 8) +
theme_minimal() +
ggplot2::guides(color = guide_legend(override.aes = list(alpha = 1))) +
ggplot2::guides(edge_color = guide_legend(override.aes = list(edge_alpha = 1)))
Created on 2022-07-04 by the reprex package (v2.0.1)
It seems I cannot remove the
alpha
level of colored edges in a ggraph legend. Because of overlapping edges, I setalpha
, but I don't want it in the legend because of visibility. With nodes I can removealpha
usingoverride.aes
, but with edges it seems I can't:Works:
ggplot2::guides(color = guide_legend(override.aes = list(alpha = 1)))
Fails:ggplot2::guides(edge_color = guide_legend(override.aes = list(alpha = 1)))