dan*_*dan 5 layout r graph ggplot2
有没有办法在dot布局中绘制DAG (a-la Rgraphviz)ggnet?
我的例子是基因本体图,取自topGO的vignette:
library(topGO)
library(ALL)
data(ALL)
data(geneList)
affyLib <- paste(annotation(ALL),"db",sep= ".")
library(package=affyLib,character.only=TRUE)
topgo.obj <- new("topGOdata",description="Simple session",ontology="BP",allGenes=geneList,geneSel=topDiffGenes,nodeSize=10,annot=annFUN.db,affyLib=affyLib)
res.fisher <- runTest(topgo.obj,algorithm="classic",statistic="fisher")
res.df <- GenTable(topgo.obj,classicFisher=res.fisher,orderBy="classicFisher",topNodes=length(score(res.fisher)))
Run Code Online (Sandbox Code Playgroud)
为方便起见,我设置:
res.df$p.value <- as.numeric(res.df$classicFisher)
Run Code Online (Sandbox Code Playgroud)
我保留了topGO graphNELp值低于0.05 的唯一节点及其祖先:
topgo.graph <- graph(topgo.obj)
sig.cutoff <- 0.05
sig.node.names <- dplyr::filter(res.df,p.value < sig.cutoff)$GO.ID
topgo.graph <- reverseArch(inducedGraph(topgo.graph,sig.node.names))
Run Code Online (Sandbox Code Playgroud)
要使用ggnet我将graphNEL图形转换为igraph:
library(ggnet)
library(network)
library(sna)
library(scales)
library(igraph)
library(intergraph)
topgo.igraph <- graph_from_graphnel(topgo.graph,name=TRUE,weight=TRUE,unlist.attrs=TRUE)
topgo.network <- asNetwork(topgo.igraph,amap=attrmap())
ggnet2(net=topgo.network,size=10,arrow.size=12,arrow.gap=0.025)
Run Code Online (Sandbox Code Playgroud)
使用Rgraphviz的dot布局是我想要ggnet打印出来的格式:
library(Rgraphviz)
nodeAttrs <- list()
edgeAttrs <- list()
graphAttrs <- getDefaultAttrs(layoutType='dot')
graphAttrs$cluster <- NULL
graphAttrs$node$shape <- 'box'
graphAttrs$node$fontsize <- '14'
nodeAttrs$label <- nodes(topgo.graph)
names(nodeAttrs$label) <- nodes(topgo.graph)
graphAttrs$edge$color <- 'black'
plot(agopen(graph=topgo.graph,name="GO",attrs=graphAttrs,nodeAttrs=nodeAttrs,edgeAttrs=edgeAttrs))
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何让ggnet在这个布局中绘制topgo.network?