专栏名称: EasyCharts
EasyCharts,易图表,我们将定期推送各种数据可视化与分析教程,包括Excel(Power BI)、Origin、Sigmaplot、GraphPad、R、Python、Matlab、Tableau、D3.js等。
目录
相关文章推荐
前端大全  ·  前端行情变了,差别真的挺大。。。 ·  昨天  
前端大全  ·  React+AI 技术栈(2025 版) ·  3 天前  
商务河北  ·  经开区“美•强•优”三重奏 ·  2 天前  
51好读  ›  专栏  ›  EasyCharts

圆形树状图(circular dendrogram)

EasyCharts  · 公众号  · 前端  · 2019-12-27 23:24

正文


输入1:

install.packages("ggraph")
library(ggraph)
install.packages("igraph")
library(igraph)
myedges "edges.xlsx");myedges
myedges1 -3]
myvalue 10,myedges [3]);myvalue
myvertices as.character(myedges1$from), as.character(myedges1$to))) ,myvalue )
myvertices$group = myedges1$from[match( myvertices$name, myedges1$to)]
head(myvertices,20)

结果1:

name     value group
1    total 10.000000  <NA>
2        I  2.390000 total
3        T  1.370000 total
4        Y  1.370000 total
5        S  1.550000 total
6        M  1.610000 total
7        k  0.700000 total
8        W  1.010000 total
9   sub-I1  1.201771     I
10  sub-I2  1.188146     I
11  sub-I3  1.158170     I
12  sub-I4  1.209947     I
13  sub-I5  1.194959     I
14  sub-I6  1.129556     I
15  sub-I7  1.189508     I
16  sub-I8  1.115931     I
17  sub-I9  1.119240     I
18 sub-I10  1.031452     I
19 sub-I11  1.024639     I
20 sub-I12  1.004201     I

输入2:

mygraph <-




    
 graph_from_data_frame(myedges1vertices=myvertices,directed = T)
 ggraph(mygraphlayout = 'dendrogram'circular = TRUE) + 
   geom_edge_diagonal(colour="black") +
   scale_edge_colour_distiller(palette = "RdPu") +
   geom_node_text(aes(x = x*1.05, y=y*1.05, filter = leaf, label=name,   
   hjust='outward'angle = -((-node_angle(x, y)+90)%%180)+90size=3, 
   colour=group), size=3, alpha=1) +
   geom_node_point(aesx = x, y=y, filter = leaf,colour=group, size=value, alpha=0.2)) +
   scale_colour_manual(valuesrep( brewer.pal(9,"Paired") , 30)) +
   scale_size_continuousrange = c(0.1,10) ) +
   theme_void() +
   theme(legend.position="none",plot.margin=unit(c(0,0,0,0),"cm")) +
   expand_limits(x = c(-1.3, 1.3), y = c(-1.3, 1.3))

结果2:

输入3:

 ggraph(mygraph, layout = 'dendrogram') + 
   geom_edge_diagonal2(aes(colour =node.group)) +
   geom_node_text(aes( filter=leaf,label=name, size=3,colour=group) ,angle=90, hjust=1, nudge_y=-0.1






请到「今天看啥」查看全文