to_igraph.Rd
Create Igraph
to_igraph(
data,
base_node = NULL,
nodes = NULL,
keep_all = T,
delimiter = "|",
is_directed = T,
exclude_base_node = F,
graph_direction = "climb",
return_tidy_graph = F,
...
)
library(asbviz)
library(tidyverse)
library(data.tree)
library(treemap)
library(ggraph)
library(grapher)
library(tidygraph)
data <- mtcars %>% rownames_to_column(var = "car") %>% as_tibble()
data("GNI2014")
GNI2014
tbl_gni <- GNI2014 %>% as_tibble()
g_tidy <-
to_igraph(
data = tbl_gni,
base_node = "The World",
nodes = c("continent", "country"),
keep_all = T,
is_directed = T,
return_tidy_graph = T
)
tbl_edges <- g_tidy %>%
activate(edges) %>%
as_tibble()
tbl_nodes <-g_tidy %>%
activate(nodes) %>%
as_tibble() %>%
mutate(id = 1:n())
tbl_gni_df <-
tbl_edges %>%
left_join(tbl_nodes %>% rename(from_name = name, from = id)) %>%
left_join(tbl_nodes %>% rename(to_name = name, to = id))
tbl_gni_df %>%
mutate(weight = 10) %>%
hc_xy(from = "from_name", to = "to_name", type = "networkgraph", weight = "weight")
graph <- to_igraph(
data = tbl_gni,
base_node = "The World",
nodes = c("continent", "country"),
keep_all = T,
is_directed = T,
return_tidy_graph = F
)
igraph::as_data_frame(graph) %>% as_tibble()
ggraph(graph, layout = 'fr') +
geom_edge_link() +
geom_node_point()