投稿问答最小化  关闭

万维书刊APP下载

R语言弦图绘制-(单细胞互作弦图)

2022/10/27 14:32:27  阅读:205 发布者:

弦图是一种非常常见的图形,表示互作联系,远的不说,就近期一直说的单细胞互作关系的展示上(iTALK---单细胞受配体互作分析及可视化(详细版教程),弦图露了很多次面!这里我们举个例子,说说简单的弦图绘制!

首先准备互作数据,设置颜色,有几个项目就设置几种颜色。这里弦图的绘制采用的是circlize包的chordDiagram函数。

setwd("D:/KS项目/公众号文章/环形弦图绘制")

# 读取数据\设置颜色

net <- read.table("df.csv", header = T, sep = ',')

library(circlize)

mycolor <- c("#DC050C", "#FB8072", "#1965B0", "#7BAFDE", "#882E72",

             "#B17BA6", "#FF7F00", "#FDB462", "#E7298A", "#E78AC3",

             "#33A02C")

绘图。

chordDiagram(

  x = net,

  grid.col = mycolor,                    

  directional = 1,                             

  direction.type = c("arrows", "diffHeight"),   

  diffHeight = -0.01,                            

  annotationTrack = c("name", "grid", "axis"),  

  annotationTrackHeight = c(0.05, 0.08),     

  link.arr.type = "big.arrow",                 

  link.sort = TRUE,                              

  link.largest.ontop = TRUE,                  

  transparency = 0.25                

)

还可以将弦取消,使用箭头连接,更加明了,连接线宽度设置数值,表示互作关系的强弱。

chordDiagram(

  x = net,

  grid.col = mycolor,                    

  directional = 1,                               

  direction.type = 'arrows',

  diffHeight = -0.01,                  

  annotationTrack = c("grid","name"),   

  annotationTrackHeight = c(0.05, 0.08),   

  link.arr.type = "triangle",

  link.sort = TRUE,                            

  link.largest.ontop = TRUE,                 

  transparency = 0.5,      

  col='#00000000',#弦的颜色,设置为无

  link.arr.lwd=net$value, #连线的宽度

  column.col  = mycolor

)

最后,我们添加上标题和legend就完成了!

#添加legend

legend("right",

       pch=20,

       legend=unique(net$SOURCE),

       bty="n",

       col =mycolor,

       cex=1,pt.cex=3,

       border="black")

title('Intercellular communication')

这样就完成了

转自:KS科研分享与服务”微信公众号

如有侵权,请联系本站删除!


  • 万维QQ投稿交流群    招募志愿者

    版权所有 Copyright@2009-2015豫ICP证合字09037080号

     纯自助论文投稿平台    E-mail:eshukan@163.com