操作系統(tǒng):win10
R版本:R-3.3.3
前期準(zhǔn)備
安裝pandoc
下載鏈接:https://pan.baidu.com/s/1nvMA1Rz (感謝 @喬布斯的同學(xué))
雙擊下載的程序包权均,進(jìn)行安裝孽椰。
命令提示符中輸入 pandoc --version
檢查安裝是否成功
安裝 networkD3 包
> source("http://bioconductor.org/biocLite.R")
> biocLite("networkD3")
繪制基因調(diào)控網(wǎng)絡(luò)圖
力導(dǎo)向圖可用于顯示復(fù)雜的網(wǎng)絡(luò)關(guān)系,這里我們用來繪制簡(jiǎn)單的基因調(diào)控網(wǎng)絡(luò)圖咳胃。
代碼如下
> genelinks <- read.table("genelinks.txt", sep="\t", header=T)
> genenodes <- read.table("genenodes.txt", sep="\t", header=T)
#讀入兩個(gè)數(shù)據(jù)文件峰尝,文件內(nèi)容及格式見下面
> head(genelinks)
source target value col
1 1 0 2 red
2 2 0 2 red
3 4 0 2 red
4 3 3 2 green
5 4 2 2 green
6 5 1 2 green
> head(genenodes)
name group
1 Gene1 gene
2 Gene2 gene
3 TF1 TF
4 miRNA1 miRNA
5 miRNA2 miRNA
6 Gene3 gene
> output <- forceNetwork(Links=genelinks, Nodes=genenodes, Source="source", Target="target", linkColour=genelinks$col, Value="value", NodeID="name", fontSize=20, Group="group", opacity=0.8, zoom=TRUE, arrows=TRUE, opacityNoHover=0.7, legend=TRUE, height=600, width=600)
#繪圖
> saveNetwork(output, "output.html", selfcontained=TRUE)
#圖像保存
結(jié)果展示(這里截取靜態(tài)圖,實(shí)際繪制結(jié)果為動(dòng)態(tài)圖)
output.jpg
參數(shù)詳解
output <- forceNetwork(Links=genelinks, #讀入基因之間的關(guān)系列表,基因以數(shù)字為編號(hào)糕档,從0開始;value可用來設(shè)置基因間連線的寬度
Nodes=genenodes, #基因信息拌喉,以對(duì)應(yīng)編號(hào)的大小排序
Source="source", #指定Links文件中的源節(jié)點(diǎn)
Target="target", #指定Links文件中的靶節(jié)點(diǎn)
linkColour=genelinks$col, #指定連線的顏色速那,默認(rèn)為單一顏色,這里用紅尿背、綠色分別表示某一基因?qū)Π谢虻恼搜觥⒇?fù)調(diào)控關(guān)系
Value="value", #設(shè)定基因間連線的寬度
NodeID="name", #指定節(jié)點(diǎn)顯示的標(biāo)簽
fontSize=20, #設(shè)定節(jié)點(diǎn)標(biāo)簽的字號(hào),單位為像素
Group="group", #對(duì)節(jié)點(diǎn)進(jìn)行分組田藐,這里可根據(jù)基因的功能進(jìn)行分組荔烧,配置不同顏色
opacity=0.8, #指定圖像的不透明度
zoom=TRUE, #是否允許圖像縮放
arrows=TRUE, #連線是否添加箭頭,顯示方向
opacityNoHover=0.7, #鼠標(biāo)懸停前汽久,節(jié)點(diǎn)標(biāo)簽的不透明度
legend=TRUE, #是否顯示圖例
height=600, #設(shè)置圖像高度
width=600 #設(shè)置圖像寬度
)
附
NetworkD3 包的完整說明 networkD3 package