桑基图

R包networkD3

示例

edges

nodes

edges$edgegroup = as.character(edges$from)
sankeyNetwork(
  Links = edges, Nodes = nodes, 
  Source = "from", Target = "to", 
  NodeID = "label", Value = "value",
  LinkGroup = "edgegroup",
  fontSize = 16, unit = "Letter(s)")
image.png

nodeID必须从0开始

R包ggplot2

file
library(ggalluvial)
library(ggplot2)

df<-read.table("sangji-GO.txt",header = T,sep = "\t")

ggplot(data =crc,aes(axis1=celltype,axis2=Description,weight=Count))+geom_stratum() +  #冲击图中的堆叠柱形图
    geom_flow(aes.flow = 'forward') + #连接线
    geom_text(stat = 'stratum', infer.label = TRUE, size = 4)+ #填充字体
    geom_alluvium(aes(fill = celltype))+ #填充颜色
    theme_bw()+theme(text = element_text(size=14),legend.position = "NULL",panel.background = element_blank(),line = element_blank(), axis.text.y = element_blank())+
    scale_x_continuous(limits=c(0.8,2.5))#调整x轴的显示
桑基图

你可能感兴趣的:(桑基图)