library(ggraph)
library(igraph)
library(dplyr)
df <- data.frame(group=c("root", "root", "a","a","b","b","b"),
subitem=c("a", "b", "x","y","z","u","v"),
size=c(0, 0, 6,2,3,2,5))
# create a dataframe with the vertices' attributes
vertices <- df %>%
distinct(subitem, size) %>%
add_row(subitem = "root", size = 0)
graph <- graph_from_data_frame(df, vertices = vertices)
ggraph(graph, layout = "circlepack", weight = size) +
geom_node_circle(aes(fill =depth)) +
# adding geom_text to see which circle is which node
geom_text(aes(x = x, y = y, label = paste(name, "size=", size))) +
coord_fixed()
library(igraph)
library(dplyr)
df <- data.frame(group=c("root", "root", "a","a","b","b","b"),
subitem=c("a", "b", "x","y","z","u","v"),
size=c(0, 0, 6,2,3,2,5))
# create a dataframe with the vertices' attributes
vertices <- df %>%
distinct(subitem, size) %>%
add_row(subitem = "root", size = 0)
graph <- graph_from_data_frame(df, vertices = vertices)
ggraph(graph, layout = "circlepack", weight = size) +
geom_node_circle(aes(fill =depth)) +
# adding geom_text to see which circle is which node
geom_text(aes(x = x, y = y, label = paste(name, "size=", size))) +
coord_fixed()
No comments:
Post a Comment