thomasp85 / ggraph

Grammar of Graph Graphics
https://ggraph.data-imaginist.com
Other
1.07k stars 112 forks source link

Legend missing if ggraph not loaded #133

Open lazappi opened 6 years ago

lazappi commented 6 years ago

I've just noticed that if you try and plot something without loading ggraph first the legends are missing:

data("highschool", package = "ggraph")
hairball <- igraph::graph_from_data_frame(highschool)
ggraph::ggraph(hairball, layout = 'kk') + 
    ggraph::geom_edge_link(ggplot2::aes(colour = year))

image

This works fine for a normal ggplot2 plot:

data("mpg", package = "ggplot2")
ggplot2::ggplot(mpg, ggplot2::aes(displ, hwy, colour = class)) + 
    ggplot2::geom_point()

image

P.S. Thanks a lot for your work on ggraph/tidygraph, they are both awesome!

lazappi commented 6 years ago

Just in case you were wondering I noticed this when trying to find the cause of this issue https://github.com/lazappi/clustree/issues/14 in my clustree package. It's probably not a normal use case so if there isn't an obvious solution might not be worth your time.

thomasp85 commented 5 years ago

This is an unfortunate side-effect of how ggplot2 searches for scales. It searches in the ggplot2 namespace and in the global search path. This means that for edge scales it won't find anything unless ggraph has been loaded.

I'm not too pleased with the situation, but I don't know what to do about it at the moment