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

Deleting isolated nodes in facet_edges() graphs #213

Open
SantiFilippo opened this issue Sep 28, 2019 · 0 comments
Open

Deleting isolated nodes in facet_edges() graphs #213

SantiFilippo opened this issue Sep 28, 2019 · 0 comments

Comments

@SantiFilippo
Copy link

SantiFilippo commented Sep 28, 2019

I am trying to facet my graph after bind_graph(). The two networks I am binding have different sets of edges: a first one only includes edges from a specific node, the second only includes edges directed to that node.
When I plot the graph, I obtain the two cloud with no isolates. When I use the facet_edges() option, I obtain the two clouds in distinct panes, but now they both include the unconnected nodes from the other graph.
I tried to solve the issue, but I could not find how.
My code is

`

Overall network

g.tot.1 <- tbl_graph(nodes = nodes, edges = fdi) %>%
activate(edges) %>% filter(sector == 'Financial Services') %>%
activate(nodes) %>% filter(!node_is_isolated()) %>%
activate(edges) %>% mutate(tofrom = ifelse(.N()$name[to] == 'DUB', 1, 2))

incoming edges

g.to.1 <- g.tot.1 %>%
filter(tofrom == 1) %>%
activate(nodes) %>% filter(!node_is_isolated())

outgoing edges

g.from.1 <- g.tot.1 %>%
filter(tofrom == 2) %>%
activate(nodes) %>% filter(!node_is_isolated())

Plot

g <- g.to.1 %>% bind_graphs(g.from.1) %>% activate(nodes) %>% filter(!node_is_isolated())

ggraph(g, layout = 'fr') +
facet_edges(~tofrom) +
geom_edge_link() +
geom_node_point(size = 5, colour = "steelblue") +
geom_node_text(aes(label = name), colour = 'black', vjust = 0.4) +
ggtitle('FDI From and To Dubai', subtitle = "Financial Sevices") +
theme_graph(foreground = 'steelblue')

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants