# The dnet package supports two ways to visualise the identified networks/graphs: 1) the network itself as a single display, 2) the same network but with multiple colorings/displays according to samples.
# To demonstrate the visuals supported, we use a random graph generated according to the ER model, and only keep the largest component.
g <- erdos.renyi.game(100, 1/100)
g <- dNetInduce
# To display the network itself, the key setting is the layout.
Since the network is represented as an object of class 'igraph', the layouts supported in the 'igraph' package can be found in the layout
page. Below is an example using a force-based algorithm proposed by Fruchterman and Reingold:
# Additionally, the dnet package also uses two other layouts/diagrams: 1) arc diagram in one-dimensional layout, and 2) circle diagram.
# To better display the network, it is advisable to incorporate community information.
In doing so, we first identify communities based on a spin-glass model and simulated annealing.
com <- igraph::spinglass.community(g, spins=25)
vgroups <- com$membership
## color nodes: according to communities
mcolors <- visColormap(colormap="rainbow")(length(com))
vcolors <- mcolors[vgroups]
## size nodes: according to degrees
vdegrees <- igraph::degree(g)
## sort nodes: first by communities and then degrees
df <- data.frame(ind=1:vcount(g), vgroups, vdegrees)
ordering <- df[order(vgroups,vdegrees),]$ind
# Now, make comparsions between different layouts
## using 1-dimensional arc diagram
(g, ordering=ordering, vertex.label.color=vcolors, vertex.color=vcolors, vertex.frame.color=vcolors, vertex.size=log(vdegrees)+0.1)
## using circle diagram (drawn into a single circle)
(g, colormap="rainbow", com=com, ordering=ordering)
## using circle diagram (drawn into multlpe circles: one circle per community)
(g, colormap="rainbow", com=com, circles="multiple", ordering=ordering)
## using a force-based algorithm proposed by Fruchterman and Reingold
(g, colormap="rainbow", layout=layout.fruchterman.reingold, vertex.color=vcolors, vertex.frame.color=vcolors, vertex.shape="sphere")
## when using force-based layout, it is also useful to highlight the communities in the background, and have edges being colored differently according whether an edge lies within a community or between communities.
mark.groups <- igraph::communities(com)
mark.col <- visColoralpha(mcolors, alpha=0.2)
mark.border <- visColoralpha(mcolors, alpha=0.2)
edge.color <- c("grey", "black")[igraph::crossing(com,g)+1]
(g, colormap="rainbow", glayout=layout.fruchterman.reingold, vertex.color=vcolors, vertex.frame.color=vcolors, vertex.shape="sphere", mark.groups=mark.groups, mark.col=mark.col, mark.border=mark.border, mark.shape=1, mark.expand=10, edge.color=edge.color)
# Now, let us look at visualising the same network but with the multiple colorings/displays according to samples.
# Assume we have 10 samples, each containing numeric information about nodes in the graph:
nnodes <- vcount(g)
nsamples <- 10
data <- matrix(runif(nnodes*nsamples), nrow=nnodes, ncol=nsamples)
rownames(data) <- V(g)$name
# In the dnet package, these sample-specific network visuals can be simply as they are provided, or samples being self-organised onto 2D landscape.
## simply as they are provided
(g, colormap="rainbow", data=data, glayout=layout.fruchterman.reingold)
## being self-organised onto 2D sample landscape (ie a sheet-shape rectangle grid)
sReorder <- dNetReorder
(g, data, feature="node", node.normalise="none")
(g, colormap="rainbow", data=data, sReorder)
## By default, 2D sample landscape is built based on node features without considering node degrees. To take into account the connectivity in the network, the information used can be on edges which are transformed from information on nodes: input data and degree. In doing so, the transformed matrix of network edges × samples are used for self-organising samples onto 2D landscape (implemented in the 'supraHex' package).
sReorder <- dNetReorder
(g, data, feature="edge", node.normalise="degree")