thomasp85 / tidygraph

A tidy API for graph manipulation
https://tidygraph.data-imaginist.com
Other
547 stars 62 forks source link

Getting node attributes for multiple morphed subraphs #159

Open jdfoote opened 2 years ago

jdfoote commented 2 years ago

I have a pretty simple use case that I'm struggling to figure out how to solve.

Basically, I want to know what the degree distribution is for each edge type. Here's a simple example:

G %>%
  activate(edges) %>%
  mutate(high_weight = weight > mean(weight)) %>%
  morph(to_split, high_weight, split_by='edges') %>%
  activate(nodes) %>%
  mutate(degree = centrality_degree(mode = 'all')) %>%
  unmorph() %>%
  as_tibble()

(I believe) the problem is that nodes are in both subgraphs, so the degree attribute in the nodes dataframe is overwritten, so it ends with just the degree of the last group in the split operation.

Is there a way to get the degree for each subgraph?

thomasp85 commented 1 year ago

Thanks - indeed only the first result is kept. I'll have to think about how to address this best