如何绘制桑基图

admin 24 2025-01-24 编辑

最近小编在看文献的过程中看见了一种新的图,名字叫做桑基图(Sankey plots),在该文献中展示的是ceRNA网络,看起来很是炫酷呀!

首先来了解下什么是桑基图,桑基图,全称为桑基能量平衡图,可以用于展示数据的变化。它的特征是能量平衡,可用于多种数据类型的可视化分析。制作工具有R,Python等编程语言。小编主要为大家介绍利用R语言来绘制桑基图。下面小编将绘制桑基图的方法推荐给大家。在这里,主要为大家介绍riverplot这个包。Riverplot包:安装与载入:install.packages("riverplot")library(riverplot)这个包中有几个功能,包括curveseg ,makeRiver, minard , plot.riverplot , riverplot-styles我们一一来看一下它们的具体作用:(1)curveseg,它主要用于绘制一个弯曲的部分,这里我们以绘制一条DNA链为例:# a DNA strand#plot.new()par( usr= c( 0, 4, -2.5, 2.5 ) )w <- 0.4cols <- c( "green", "blue" )init <- c( -0.6, -0.4 )pos <- c( 1, -1 )step <- 0.5for( i in rep( rep( c( 1, 2 ), each= 2 ), 5 ) ) {curveseg( init[i], init[i] + step, pos[1], pos[2], width= w, col= cols[i] )init[i] <- init[i] + steppos <- pos * -1}图形显示:

(2)makeRiver,它用于创建一个新的riverplot对象例:绘制一个简单的桑基图nodes <- c( LETTERS[1:4] )edges <- list( A= list( D= 10 ), B= list( D= 10 ),C=list(D=10) )r <- makeRiver( nodes, edges, node_xpos= c( 1,1,1,2 ),node_labels= c( A= "Node A", B= "Node B", C= "Node C",D="Node D" ),node_styles= list( A= list( col= "yellow" ),B=list(col="red"),C=list(col="green")) )plot( r )图形显示:

(3)minard:这是查尔斯约瑟夫米纳德用来生成著名图表的数据集例:data( minard ) ##导入数据nodes <- minard$nodes  ##定义点edges <- minard$edges  ##定义边colnames( nodes ) <- c( "ID", "x", "y" )colnames( edges ) <- c( "N1", "N2", "Value", "direction" )edges$col <- c( "#e5cbaa", "black" )[ factor( edges$direction ) ] ##着色edges$edgecol <- "col"##生成riverplot对象和样式river <- makeRiver( nodes, edges )style <- list( edgestyle= "straight", nodestyle= "invisible" )plot( river, lty= 1, default_style= style )图形显示:

(4)plot.riverplot:创建一个Sankey图我们以包中自带的例子为例:x <- riverplot.example()plot(x)plot(x, srt=90, lty=1)图形显示:

(5)riverplot-styles:这是一个调整Riverplot样式的函数例:##查看默认样式##default.style()ex <- riverplot.example()  ##创建一个riverplot的实例ds <- default.style()plot( ex, default_style= ds )图形显示:

#具有未指定样式的节点现在将是半透明红色ds[["col"]] <- "#FF000099"plot( ex, default_style= ds )图形显示:

这就是基本的桑基图绘制,具体应用还需要大家自己慢慢钻研呀~参考Construction and comprehensive analysis of a ceRNA network to reveal potential prognostic biomarkers for hepatocellular carcinoma.

欢迎关注

TCGA | 小工具 | 数据库 |组装| 注释 |   基因家族  |  Pvalue

基因预测  |bestorf |  sci | NAR | 在线工具 | 生存分析 | 热图

 生信不死 | 初学者 | circRNA | 一箭画心| 十二生肖 | circos

 舞台|基因组 | 黄金测序 | 套路 | 杂谈组装 |  进化 | 测序简史

如何绘制桑基图

上一篇: 质粒构建工具推荐,实验室必备的分子克隆利器
下一篇: 美国网友热议:中国安全吗?
相关文章