circle packing with ggraph. Circles in lower hierarchies are too big

343 Views Asked by At

I have been trying to generate a simple circular packing graph with ggraph. However, I get the following result with my data that displays internal circles that are too big for the resident circle:

circle packing image

enter image description here

Code:

library(dplyr)
library(igraph)
library(ggraph)
library(viridis)
dfs <- structure(list(group = c("root", "Epithelial", "Epithelial", "Epithelial", "Epithelial", "Epithelial", "Epithelial", "Epithelial", "Epithelial", "root", "Hematopoietic", "Hematopoietic", "Hematopoietic", "Hematopoietic", "root", "Stromal ", "Stromal ", "Stromal ", "Stromal ", "Stromal ", "Stromal ", "Stromal "), subitem = c("Epithelial", "Adipose Epithelium", "Bladder Epithelial", "Keratinized Epithelium", "Mammary Epithelium", "Mesothelium", "Pancreatic Epitheliium", "Renal Epithelium", "Respiratory Epithelium", "Hematopoietic", "Erythrocyte", "Leukocytes", "Lymphocytes", "Myeloid Cells", "Stromal ", "Astrocytes", "Chondroblast", "Fibroblasts", "Mesenchymal Stromal", "Muscle Satellite Cell", "Pericytes", "Smooth Muscle"), size = c(3.66, 0.18, 0.07, 0.01, 1.22, 1.81, 0.03, 0.01, 0.32, 1.11, 0.17, 0.71, 0.11, 0.11, 31.99, 0.04, 15.13, 5.32, 6.83, 4.41, 0.15, 0.1)), class = "data.frame", row.names = c(NA, -22L))

vertices <- dfs %>% 
  distinct(subitem, size) %>% 
  add_row(subitem = "root", size = 0)

graph <- graph_from_data_frame(dfs, vertices = vertices)

p <- ggraph(graph, layout = "circlepack", weight = size) + 
  geom_node_circle(aes(fill =depth), show.legend = F) 

p

Can anyone please advise on how I can fix this? I thought it may be an issue with the lowest hierarchy (leaf) values being too big, however if I divide all of these by 10 I get the same problem, so I am clearly missing something.

1

There are 1 best solutions below

0
On

This appears to be an issue with the backend of ggraph or a dependency used for internal calculations of the circle packing. The outputs from p$data are being correctly plotted.

Open a ticket with the package maintainers at https://github.com/thomasp85/ggraph/issues and they should be able to fix the issue.