经管之家送您一份
应届毕业生专属福利!
求职就业群
感谢您参与论坛问题回答
经管之家送您两个论坛币!
+2 论坛币
求助,在跑网站上给出的示例代码的时候遇到了个小问题,代码如下:
- # Libraries
- library(ggraph)
- library(igraph)
- library(tidyverse)
- # create a data frame giving the hierarchical structure of your individuals
- d1=data.frame(from="origin", to=paste("group", seq(1,10), sep=""))
- d2=data.frame(from=rep(d1$to, each=10), to=paste("subgroup", seq(1,100), sep="_"))
- hierarchy=rbind(d1, d2)
- # create a dataframe with connection between leaves (individuals)
- all_leaves=paste("subgroup", seq(1,100), sep="_")
- 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)) )
- connect$value=runif(nrow(connect))
- # create a vertices data.frame. One line per object of our hierarchy
- vertices = data.frame(
- name = unique(c(as.character(hierarchy$from), as.character(hierarchy$to))) ,
- value = runif(111)
- )
- # Let's add a column with the group of each name. It will be useful later to color points
- vertices$group = hierarchy$from[ match( vertices$name, hierarchy$to ) ]
- # Create a graph object
- mygraph <- graph_from_data_frame( hierarchy, vertices=vertices )
- # The connection object must refer to the ids of the leaves:
- from = match( connect$from, vertices$name)
- to = match( connect$to, vertices$name)
- ggraph(mygraph, layout = 'dendrogram', circular = TRUE) +
- geom_node_point(aes(filter = leaf, x = x*1.05, y=y*1.05)) +
- theme_void() +
- geom_conn_bundle(data = get_con(from = from, to = to), alpha=0.2, colour="skyblue", width=0.9, tension=0.7) +
- geom_conn_bundle(data = get_con(from = from, to = to, value=connect$value), aes(colour=value)) +
- scale_edge_color_continuous(low="white", high="red")
复制代码倒数第二步关联图上色的时候报错:
- `data` must be uniquely named but has duplicate elements
复制代码请问是什么原因?谢谢
扫码加我 拉你入群
请注明:姓名-公司-职位
以便审核进群资格,未注明则拒绝
|