简体   繁体   中英

Using ggraph's circlepack layout in R

I am trying to create a graph using ggraph's circlepack layout in R.

The code I am using is below.

df <- data.frame(PID = c("root", "c11111", "c22222", "c11111", "c11111"),    
                 ID = c("c11111", "c22222", "s33333", "c44444", "c55555"), 
                 size = c(1, 20000, 10000, 1, 1))

vertices <- df %>% 
  distinct(ID, size) %>% 
  add_row(ID = "root", size = 0)

mygraph <- graph_from_data_frame(df, vertices = vertices)

ggraph(mygraph, layout = 'circlepack') +
  geom_node_circle(aes(fill = size)) +
  theme_void() +
  geom_node_label(aes(label = name))

I am not sure why c22222 is not appearing within c33333 - I'm only seeing c33333.

I'd greatly appreciate any advice or ideas about what's going on.

Your code is actually correct, but your labels are overlapping If you add some jitter to your plot you'll see c22222

ggraph(mygraph, layout = 'circlepack') +
  geom_node_circle(aes(fill = size)) +
  theme_void() +
  geom_node_label(aes(label = name),position=position_jitter(width=.2,height=.2))

Note this plot currently does not use the size property of your graph. You should add weight=size

ggraph(mygraph, layout = 'circlepack', weight=size)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM