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

allow using ggraph *without* attaching it #85

Closed
maxheld83 opened this issue Sep 8, 2017 · 2 comments
Closed

allow using ggraph *without* attaching it #85

maxheld83 opened this issue Sep 8, 2017 · 2 comments

Comments

@maxheld83
Copy link

maxheld83 commented Sep 8, 2017

library(ggraph)
library(igraph)
graph <- igraph::graph_from_data_frame(highschool)

# Not specifying the layout - defaults to "auto"
g <- ggraph(graph) + 
  geom_edge_link(aes(colour = factor(year))) + 
  geom_node_point()
g

This is fine:

rplot

However, when plotted without ggraph attached, the legend is missing and there are different colors.

detach(name = "package:ggraph", unload = TRUE)
g  # without legend

rplot01

I am (wildly) guessing this has something to do with the black magic of the edge aesthetics that ggraph does.

This is not a problem in a script use (where usually you'd have library(ggraph)), but it can be a little odd in in-package use:
I'd rather not import the entire ggraph namespace, but without that, my examples on ggraph-derivative functions will not work properly (as in the above).

The behavior also strikes me as a little unexpected because, class(g) is only "gg" "ggplot", which makes me think that just ggplot::print.ggplot() ought to do the trick.

Is there any chance this could be changed?

@thomasp85
Copy link
Owner

This is unfortunately outside the hands of ggraph. It all boils down to how ggplot2 itself handles guides and legends. Currently it is looking on the search path for functions of the right name so you'll need to import these from ggraph in order to get it to work... hopefully the guide system will get an overhaul and adopt the ggproto approach someday, but as I said this is ggplot2 stuff, not ggraph

@maxheld83
Copy link
Author

thanks so much for clarifying!

Do you have any recommendation for how to go about this if ggraph is used inside a package?

I have an autoplot method that uses ggraph, and I don't want to Imports: ggraph in the DESCRIPTION, because it's a rare use case.

So for now, I just remind users to library(ggraph) when they use this particular autoplot method.

maxheld83 added a commit to maxheld83/pensieve that referenced this issue Sep 9, 2017
as per thomasp85/ggraph#85 it is actually impossible (for now) to render g without `library(ggraph)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants