[关闭]
@agpwhy 2022-05-12T14:03:51.000000Z 字数 1592 阅读 274

王胖的生信笔记第42期-花瓣图

花瓣图是啥

这应该不是一个官方的名称,是看到一个叫做ccgraph的包里讲到的。cc这个词来源于《一个馒头引发的血案》里的圆环套圆环,可以用在很多地方。

image-20220512213248027

A Prospective Study of Circulating Tumor DNA to Guide Matched Targeted Therapy in Lung Cancers

这篇文章里讲到的用处是内层标明测序在若干基因发现的 SNP/Indel/CNV 等各类突变,外层来展示各类基因。同时点的大小可以表示某参数的大小。

image-20220512212841049

拿新冠数据练练手

ccgraph官方教程是自己生成一个模拟的宏基因组数据,还有一个是2014年的世界经济数据,我们来点真实的。

新冠数据的来源可以使用之前笔记写过的nCov2019这个包。

  1. library(tidyverse)
  2. library(ggraph)
  3. library(ccgraph)
  4. library(nCov2019)
  5. library(treemap)
  6. library(export)
  7. res <- query()
  8. dat <- res$latest$detail

先来看看大概数据情况

  1. treemap(dat,index=c("continent","country"),vSize = "cases")

Treemap_00

数据转换

这个包比较好的一个方面,就是把网络图node,edge的设置简单化了。

  1. country_index <- c("continent","country")
  2. nodes_country <- gather_graph_node(dat,index = country_index, value = "cases",root="world")
  3. edges_country <- gather_graph_edge(dat,index = country_index,root="world")
  4. library(tidygraph)

然后再结合node和edge转为ggraph能做图的格式。

  1. graph_country <- tbl_graph(nodes_country,edges_country)
  2. gc <- ggraph(graph_country,layout = 'dendrogram', circular = TRUE) +
  3. geom_edge_diagonal(aes(color=node1.node.branch),alpha=1/3) + geom_node_point(aes(size=node.size,color=node.branch),alpha=1/3) + coord_fixed() + theme(legend.position = "none")

image-20220512215116894

不过这个时候,是没有内外层环的文字的。按照教程添加一下文字,修改一下视觉效果。

  1. gc1 <- gc + scale_size(range = c(0.5, 40)) +
  2. geom_node_text(
  3. aes(
  4. x = 1.0175 * x, #这边前面系数是外层文字环的横径
  5. y = 1.0175 * y,#这边前面系数是外层文字环的竖径
  6. label = node.short_name,
  7. angle = -((-node_angle(x, y) + 90) %% 180) + 90,
  8. filter = leaf,
  9. color = node.branch
  10. ),
  11. size = 3,
  12. hjust = 'outward'
  13. ) +
  14. geom_node_text(
  15. aes(
  16. label = node.short_name,
  17. filter = !leaf,
  18. color = node.branch
  19. ),
  20. fontface = "bold",
  21. size = 6,
  22. family = "sans"
  23. ) +
  24. theme_void() +
  25. theme(legend.position = "none") +
  26. coord_cartesian(xlim =c(-1.5, 1.5), ylim = c(-2, 2))

最后展示下效果

country

还能直接输出成ppt哦,改起来更方便(这个下次再水一个笔记)。

image-20220512215536499

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注