thomasp85 / ggraph

Grammar of Graph Graphics
https://ggraph.data-imaginist.com
Other
1.08k stars 116 forks source link

facet_graph, number of rows #334

Closed DidDrog11 closed 10 months ago

DidDrog11 commented 1 year ago

Hi, have looked elsewhere and cannot seem to find if this is addressed.

I have graphs from 8 timepoints I'd like to plot as a single image. Facetting on the timepoint works well and I produce a facet_graph with 8 multiples. Is there a way to specify these multiples to occupy 2 or more rows as it is quite difficult to see them on a single plot.

image

landuse_graph <- readRDS(gzcon(url("https://github.com/DidDrog11/chapter_4/raw/main/data/rodent_landuse_networks.rds")))

example <- landuse_graph$agriculture

bind_graphs(example) %>%
    ggraph(layout = "fr") +
    geom_edge_link() +
    geom_node_point(aes(colour = Species), size = 3) +
    facet_graph(~ Visit, row_type = "node") +
    labs(colour = "Species",
         title = paste0(unique(bind_graphs(x) %>%
                                 pull(Landuse))),
         x = element_blank(),
         y = element_blank(),
         caption = "30m") +
    theme_bw() +
    theme(axis.text.x = element_blank(),
          axis.text.y = element_blank(),
          axis.ticks = element_blank(),
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank())
schochastics commented 1 year ago

facet_graph() is based on facet_grid() so there is no way to specify more rows without an additional variable. facet_nodes() is based on faced_wrap() and you can change the number of rows

library(igraph)
library(ggraph)
library(tidygraph)
landuse_graph <- readRDS(gzcon(url("https://github.com/DidDrog11/chapter_4/raw/main/data/rodent_landuse_networks.rds")))

example <- landuse_graph$agriculture

bind_graphs(example) %>%
  ggraph(layout = "fr") +
  geom_edge_link() +
  geom_node_point(aes(colour = Species), size = 3) +
  facet_nodes(~ Visit, nrow=2) +
  theme_bw() +
  theme(axis.text.x = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank())
#> Warning: Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
#> ℹ Please use `linewidth` in the `default_aes` field and elsewhere instead.

Created on 2023-02-07 with reprex v2.0.2