Wednesday, 1 January 2020

Code for making color pack visualization in R using custom dataset

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()

No comments:

Post a Comment

what is a good PhD contribution?

When PhD candidates embark on their thesis journey, the first thing they will likely learn is that their research must be a “significant ori...