knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(nestedcats)

library(tidyverse)
library(tidygraph)
library(ggraph)
library(collapsibleTree)
ghg_edges_df <- read_csv(here::here("data-raw/ghg_cats_edges.csv"))

ghg_nodes_df <- read_csv(here::here("data-raw/ghg_cats_nodes.csv")) %>%
  rename(id = name)

ghg_tg <- tbl_graph(nodes = ghg_nodes_df,
                    edges = ghg_edges_df) %>%
  activate(nodes) %>%
  mutate(lbl = glue::glue("id: {id}")) %>%
  mutate(leaf = node_is_leaf(),
         root = node_is_root())

The Edge Data:

ghg_edges_df

Tree Visual using ggraph package:

# root red, leafs green, labeled nodes -- layout requires directed edges away from the root.
ghg_tg %>%
  mutate(leaf = node_is_leaf(), root = node_is_root()) %>%
  ggraph(layout = 'tree') +
  geom_edge_diagonal() +
  geom_node_point(aes(filter = leaf, label = id), colour = 'forestgreen', size = 20) +
  geom_node_point(aes(filter = root, label = id), colour = 'firebrick', size = 20) +
  geom_node_text(aes(label = id)) +
  theme_graph()

Collapsible Tree widget using collapsibleTree package:

graph_convert_edgelistdf_to_parentdf(ghg_edges_df) %>%
  collapsibleTreeNetwork()


jameelalsalam/nestedcats documentation built on June 2, 2020, 8:16 p.m.