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

Feature request: facet_components #239

Closed
wdkrnls opened this issue Mar 28, 2020 · 2 comments
Closed

Feature request: facet_components #239

wdkrnls opened this issue Mar 28, 2020 · 2 comments

Comments

@wdkrnls
Copy link

wdkrnls commented Mar 28, 2020

The current faceting tools force keeping all nodes presented (if invisibly) on all facets. I'm looking for the functionality to analyze my graph by breaking it up into subgraphs. My strategy so far has been to try and isolate these subgraphs by cutting edges to produce completely disconnected components. I have managed a hack using facet_nodes which only shows the nodes and edges of each component, but each facet has massive whitespace gaps where the other components would be. Reading through issue #136 it seems that my request is slightly different, because I not only want to change what nodes (and edges) appear across facets, but also seek to reposition the location of nodes shown across each facet to focus on each component in isolation. Does that make sense? I suspect you might want a new facetting function facet_components to do this. I would also prefer to have some way to show groups of similar components shown together in a facet_grid style arrangement as well.

@mkoohafkan
Copy link

mkoohafkan commented Oct 28, 2020

I think this will be related to igraph::component_wise. Or perhaps it involves adding an offset to the coordinates generated by create_layout(), so that the result is achievable via facet_wrap(scales = "free").

Technically this is possible using facet_wrap(), you just need to assign the component ID as an attribute of both the nodes and the edges:

g1 = create_ring(10) %N>%
  mutate(label = "A") %E>%
  mutate(label = "A")
g2 = create_ring(5) %N>%
  mutate(label = "B") %E>%
  mutate(label = "B")

g = bind_graphs(g1, g2)
ggraph(g) +
  geom_edge_link() +
  geom_node_point() +
  facet_wrap(~label, scales = "free")

image

@thomasp85
Copy link
Owner

You can do this directly with facet_nodes() using tidygraph algorithms

g <- bind_graphs(create_ring(10), create_ring(5))
ggraph(g) +
  geom_edge_link() +
  geom_node_point() +
  facet_nodes(~tidygraph::group_components(), scales = "free")
#> Using "stress" as default layout

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