0

I'm puzzled about facetting a graph in R ggraph package

library(tidyverse)
library(ggraph)
library(igraph)
set.seed(100)
yr=c(2013,2014,2015,2016)
x=data.frame(from=LETTERS[sample(26,100,replace = T)],
         to=paste0(letters[sample(26,100,replace = T)],'a'),
         year=sample(yr,100,replace = T))

graph <- graph_from_data_frame(x)
graph%>%ggraph(layout = 'kk') + 
  geom_edge_fan(show.legend = FALSE) + 
  geom_node_point() + 
  facet_edges(~year) 

enter image description here Why the faceted graph show unlink points when all vertices are connected to some other vertice? and how can i use different shape to represent from and to vertices? How can I add text label to the graph - I tried geom_node_point(aes(labels = V(graph)$name)) and that didn't work well.

thanks

santoku
  • 3,297
  • 7
  • 48
  • 76
  • 1
    You have just faceted the edges and not the vertices, so all vertices are in each facet while only the edges corresponding to the facet are in in each facet. To add text use `geom_node_text(aes(label = name))` – missuse Nov 03 '17 at 09:30
  • thanks so much for solving the mystery! geom_edges make sense and not make sense at the same time, if points are linked by edges, wonder why would they stay when faceted. i tried geom_graph(~year) or +geom_nodes(~year). so far those didn't work either. maybe i need to change the syntax – santoku Nov 03 '17 at 14:50
  • @santoku see https://stackoverflow.com/questions/75598414/small-multiples-plots-replicating-entire-network-in-each-panel-in-ggraph, i assume that is the question you may have meant to ask – alexpghayes Mar 01 '23 at 00:14

0 Answers0