====== 宏基因组物种top10全层级桑基流向图(sankeyD3) ======
展示种水平的物种在全部层级上的丰度信息
===== 输入数据 =====
分组信息:group.list
B001 G1
B002 G1
B003 G1
B004 G1
B005 G1
B006 G1
指定物种的全部层级信息:tax.txt
k__Bacteria;p__Chlamydiae;c__Chlamydiia;o__Chlamydiales;f__Chlamydiaceae;g__Chlamydia;s__Chlamydia abortus
k__Bacteria;p__Proteobacteria;c__Gammaproteobacteria;o__Pseudomonadales;f__Pseudomonadaceae;g__Pseudomonas;s__Pseudomonas fragi
k__Bacteria;p__Proteobacteria;c__Gammaproteobacteria;o__Enterobacterales;f__Enterobacteriaceae;g__Escherichia;s__Escherichia coli
标准交付结果中:Unigenes.absolute.total.tax.xls
===== 输出数据后需要手动整理一下 =====
#这一部分待完善
source target value
Bacteria Proteobacteria 259448081
Proteobacteria Gammaproteobacteria 236402001.9
Gammaproteobacteria Pseudomonadales 152013077
Pseudomonadales Pseudomonadaceae 74632447.24
Pseudomonadaceae Pseudomonas 74603074.6
Pseudomonas Pseudomonas fragi 16409742.58
Bacteria Chlamydiae 28479113.74
Chlamydiae Chlamydiia 28478395.54
Chlamydiia Chlamydiales 28474661.59
Chlamydiales Chlamydiaceae 28472728.3
Chlamydiaceae Chlamydia 28472724.78
Chlamydia Chlamydia abortus 22096800.37
===== 在本地安装并调用sankeyD3 =====
#setwd("E:\\personal_demand\\sankeyd3\\sankey20230509-G2")
require(sankeyD3)
require(xlsx)
require(magrittr)
require(webshot)
#shiny::runGitHub("fbreitwieser/sankeyD3", subdir="inst/examples/shiny")
#URL <- paste0("https://cdn.rawgit.com/christophergandrud/networkD3/",
# "master/JSONdata/energy.json")
#Energy <- jsonlite::fromJSON(URL)
# Plot
links <- read.xlsx("result.xlsx",sheetIndex = 1)
nodes <- data.frame(name=c(as.character(links$source), as.character(links$target)) %>% unique())
links$IDsource <- match(links$s, nodes$name)-1
links$IDtarget <- match(links$t, nodes$name)-1
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
nodeWidth =15,units = 'TWh',
colourScale = JS("d3.scaleOrdinal().range(d3.schemeCategory20)"),
numberFormat=".0f",fontSize = 10,
nodeCornerRadius=3,nodeShadow = T,
# linkColor = "Source",
height=600,width=1200)
p
saveNetwork(p,"sankeyG2.html")
#webshot("sankeyG2.html" , "sankey.pdf",vwidth = 100,vheight = 50)
===== 最终结果展示 =====
{{:sankey.png?400|}}