ggraph
ggraph copied to clipboard
removing arrowheads in legend
Is there a way to remove arrowheads in the legend? Something like the below would be nice (the guides part)
library(igraph)
library(ggraph)
set.seed(538)
g <- sample_gnp(n = 30,p = 0.1,directed = T)
E(g)$type <- sample(c(F,T),ecount(g),replace = T)
ggraph(g,layout = "kk")+
geom_edge_link(aes(col = type),
arrow = arrow(type = "closed",length = unit(12,"pt")),
end_cap = circle(5,"pt"))+
geom_node_point(size = 5)+
theme_graph()+
guides(edge_colour = guide_legend(override.aes = list(arrow = NULL)))

What works is overwriting the draw_key function of GeomEdgePath ( link to similar solution for ggplot):
draw_key_line <- function(data, params, size) {
grid::segmentsGrob(0.1, 0.5, 0.9, 0.5,
gp = grid::gpar(col = alpha(data$edge_colour, data$edge_alpha),
lwd = data$edge_width * .pt,
lty = data$edge_linetype,
lineend = "butt"), arrow = NULL)
}
# override legend drawing function for GeomEdgePath
GeomEdgePath$draw_key <- draw_key_line
Don't think that this should be the preferred solution
This should really be fixed at the ggplot2 level. The problem is that arrow is kind of a special aesthetic not part of gpar()