楼主: zzbb2266
2948 2

[问答] R Graph Gallery中环状关联图示例运行报错 [推广有奖]

  • 0关注
  • 0粉丝

大专生

41%

还不是VIP/贵宾

-

威望
0
论坛币
13 个
通用积分
1.0179
学术水平
2 点
热心指数
2 点
信用等级
0 点
经验
227 点
帖子
25
精华
0
在线时间
67 小时
注册时间
2018-9-11
最后登录
2020-4-17

楼主
zzbb2266 发表于 2018-11-16 09:41:30 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
求助,在跑网站上给出的示例代码的时候遇到了个小问题,代码如下:
  1. # Libraries
  2. library(ggraph)
  3. library(igraph)
  4. library(tidyverse)

  5. # create a data frame giving the hierarchical structure of your individuals
  6. d1=data.frame(from="origin", to=paste("group", seq(1,10), sep=""))
  7. d2=data.frame(from=rep(d1$to, each=10), to=paste("subgroup", seq(1,100), sep="_"))
  8. hierarchy=rbind(d1, d2)

  9. # create a dataframe with connection between leaves (individuals)
  10. all_leaves=paste("subgroup", seq(1,100), sep="_")
  11. connect=rbind( data.frame( from=sample(all_leaves, 100, replace=T) , to=sample(all_leaves, 100, replace=T)), data.frame( from=sample(head(all_leaves), 30, replace=T) , to=sample( tail(all_leaves), 30, replace=T)), data.frame( from=sample(all_leaves[25:30], 30, replace=T) , to=sample( all_leaves[55:60], 30, replace=T)), data.frame( from=sample(all_leaves[75:80], 30, replace=T) , to=sample( all_leaves[55:60], 30, replace=T)) )
  12. connect$value=runif(nrow(connect))

  13. # create a vertices data.frame. One line per object of our hierarchy
  14. vertices = data.frame(
  15.   name = unique(c(as.character(hierarchy$from), as.character(hierarchy$to))) ,
  16.   value = runif(111)
  17. )
  18. # Let's add a column with the group of each name. It will be useful later to color points
  19. vertices$group = hierarchy$from[ match( vertices$name, hierarchy$to ) ]


  20. # Create a graph object
  21. mygraph <- graph_from_data_frame( hierarchy, vertices=vertices )

  22. # The connection object must refer to the ids of the leaves:
  23. from = match( connect$from, vertices$name)
  24. to = match( connect$to, vertices$name)

  25.   ggraph(mygraph, layout = 'dendrogram', circular = TRUE) +
  26.   geom_node_point(aes(filter = leaf, x = x*1.05, y=y*1.05)) +
  27.   theme_void() +
  28.   geom_conn_bundle(data = get_con(from = from, to = to), alpha=0.2, colour="skyblue", width=0.9, tension=0.7) +
  29.   geom_conn_bundle(data = get_con(from = from, to = to, value=connect$value), aes(colour=value)) +
  30.   scale_edge_color_continuous(low="white", high="red")
复制代码
倒数第二步关联图上色的时候报错:

  1. `data` must be uniquely named but has duplicate elements
复制代码
请问是什么原因?谢谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:gallery GRAPH 运行报错 GRAP RAP

沙发
zzbb2266 发表于 2018-11-16 10:45:22

藤椅
lgt870305 发表于 2023-2-3 21:22:57
请问您解决了吗

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-4 13:13