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

Some scale_edge_* only work when ggraph is loaded #75

Closed
Ax3man opened this issue May 29, 2017 · 4 comments
Closed

Some scale_edge_* only work when ggraph is loaded #75

Ax3man opened this issue May 29, 2017 · 4 comments

Comments

@Ax3man
Copy link

Ax3man commented May 29, 2017

It appears some scales only work when ggraph is actually loaded. When referring to them with :: the correct guide cannot be found. When the guide is manually specified, the scale does work (with a warning), but no guide is shown.

data('highschool', package = 'ggraph')
graph <- igraph::graph_from_data_frame(highschool)

ggraph::ggraph(graph, layout = 'kk') + 
  ggraph::geom_edge_link(ggplot2::aes(color = year)) + 
  ggraph::scale_edge_color_gradient()
# Error in get(as.character(FUN), mode = "function", envir = envir) : 
#   object 'guide_edge_colourbar' of mode 'function' was not found

ggraph::ggraph(graph, layout = 'kk') + 
  ggraph::geom_edge_link(ggplot2::aes(color = year)) + 
  ggraph::scale_edge_color_gradient(guide = ggraph::guide_edge_colorbar())
# Warning message:
#   In guide_train.colorbar(guide, scale) :
#   colorbar guide needs colour or fill scales.

These examples do work after library(ggraph).

I believe this will be a problem for code in packages, as requireNamespace does not appear to alleviate the problem.

@thomasp85
Copy link
Owner

This is an unfortunate result of how scale extensions are made in ggplot2 and outside the reach of ggraph or any other extension package. The solution is to import and reexport the needed function in your own package...

@Ax3man
Copy link
Author

Ax3man commented May 29, 2017

Ok, that solution is fine. For future visitors, including this solved it for me (using roxygen):


#' @importFrom ggraph guide_train.edge_colourbar
#' @export
ggraph::guide_train.edge_colourbar

Thanks Thomas!

@thomasp85
Copy link
Owner

Thanks @Ax3man

@llrs
Copy link

llrs commented Apr 19, 2018

I don't know if it is the way I use packages, but I thought I couldn't modify the color gradient of edges because I didn't see anything in their vignette. Thank for mentioning this here (as well as on #25) !

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

3 participants