R中的circlepack图

时间:2019-02-13 19:05:40

标签: r ggplot2 ggraph

我正在尝试在数据框中绘制一个 circlepack 的图,但是我没有成功。

我想为每个人画一个圆,例如S003,属于该个人的类别。大小表示每个人每个班级上课的时间。

曾经尝试使用how to use circle pack layout in ggraph library in rhttps://www.r-graph-gallery.com/315-hide-first-level-in-circle-packing/这两个线程,但无法做到这一点。

test <- data.frame(individual = c("S003", "S003", "S004", "S004","S004", "S009", "S009", 
                                  "S016", "S016", "S016", "S016", "S025", "S025", "S027",
                                  "S027", "S035", "S035", "S035", "S035", "S036", "S036", 
                                  "S036", "S042", "S042", "S042", "S042" , "S042", "S042",
                                  "S043", "S043", "S043", "S045", "S045", "S045", "S045", 
                                  "S045", "S045", "S047" , "S047", "S047", "S047", "S047"),
                   class = c("NMF1", "NMF1", "NMF1", "NMF3", "NMF3", "NMF4", "NMF2", 
                             "NMF3", "NMF3", "NMF3" ,"NMF2", "NMF4", "NMF2", "NMF3", 
                             "NMF1", "NMF4", "NMF2", "NMF4", "NMF4", "NMF1", "NMF1", 
                             "NMF1", "NMF3", "NMF4", "NMF4", "NMF4", "NMF4", "NMF4", 
                             "NMF2", "NMF3", "NMF3" ,"NMF2", "NMF2", "NMF3", "NMF1", 
                             "NMF2", "NMF2", "NMF2", "NMF2", "NMF4", "NMF2", "NMF2"), 
                   count= c("2", "2", "1", "2", "2", "1", "2", "3", "3", "3", "1", "1",
                            "1", "1", "1", "3", "1", "3", "3", "1", "1", "1", "1", "5",
                            "5", "5", "5", "5", "1", "2" , "2", "4", "4", "1", "1", "4",
                            "4", "4", "4", "1", "4", "4"))

vertices <- test %>% distinct(class, count)
graph <- graph_from_data_frame(test, vertices = vertices)
Error in graph_from_data_frame(test, vertices = vertices) : 
  Duplicate vertex names

0 个答案:

没有答案