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

removing arrowheads in legend #182

Open
schochastics opened this issue Jul 23, 2019 · 1 comment
Open

removing arrowheads in legend #182

schochastics opened this issue Jul 23, 2019 · 1 comment

Comments

@schochastics
Copy link
Contributor

schochastics commented Jul 23, 2019

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))) 

example

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

@thomasp85
Copy link
Owner

This should really be fixed at the ggplot2 level. The problem is that arrow is kind of a special aesthetic not part of gpar()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants