3

I am doing some exploratory network analysis with the tidygraph package. I am trying to produce a faceted plot with my data using ggraph package. I created 2 different tbl_graph objects, which I bound together using the bind_graphs function.

The code I am using is:

# 1) Creating full graph
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)) 

# 2) creating "to DUB" graph 
g.to.1 <- g.tot.1 %>%
  filter(tofrom == 1) %>%
  activate(nodes) %>% filter(!node_is_isolated()) %>%
  
# 3) Creating "from DUB" graph
g.from.1 <- g.tot.1 %>%
  filter(tofrom == 2) %>%
  activate(nodes) %>% filter(!node_is_isolated()) %>%

# Binding graphs and plotting the result
ggraph(bind_graphs(g.to.1, g.from.1), layout = 'fr') %>%
  facet_edges(~tofrom) + 
  geom_edge_link(arrow = arrow()) +
  #geom_node_point(size = 5, colour = 'steelblue') +
  #geom_node_text(aes(label = iso), colour = 'black', vjust = 0.4) +
  ggtitle('FDI From and To Dubai') +
  theme_graph(foreground = 'steelblue')

Despite a large number of warnings, I still obtain a faceted graph. However, the faceted graphs still plot all the isolates, despite the filter(!node_is_isolated()) call in both the subgraphs. This does not happen when I avoid specifying the facet_edges option.

Any help would be greatly appreciated.

Eric Leung
  • 2,354
  • 12
  • 25
Filippo Santi
  • 109
  • 1
  • 8

0 Answers0