# \donttest{
## From adjacency matrix
# Un-weighted
adjacency <- SimulateAdjacency(pk = 20, topology = "scale-free")
plot(Graph(adjacency))
# Weighted
adjacency <- adjacency * runif(prod(dim(adjacency)))
adjacency <- adjacency + t(adjacency)
plot(Graph(adjacency, weighted = TRUE))
# Node colours and shapes
plot(Graph(adjacency, weighted = TRUE, node_shape = "star", node_colour = "red"))
## From stability selection outputs
# Graphical model
set.seed(1)
simul <- SimulateGraphical(pk = 20)
stab <- GraphicalModel(xdata = simul$data)
plot(Graph(stab))
# Sparse PLS
if (requireNamespace("sgPLS", quietly = TRUE)) {
set.seed(1)
simul <- SimulateRegression(n = 50, pk = c(5, 5, 5), family = "gaussian")
x <- simul$xdata
y <- simul$ydata
stab <- BiSelection(
xdata = simul$xdata, ydata = simul$ydata,
family = "gaussian", ncomp = 3,
LambdaX = seq_len(ncol(x) - 1),
implementation = SparsePLS
)
plot(Graph(stab))
}
## Tools from other packages
# Applying some igraph functionalities
adjacency <- SimulateAdjacency(pk = 20, topology = "scale-free")
mygraph <- Graph(adjacency)
igraph::degree(mygraph)
igraph::betweenness(mygraph)
igraph::shortest_paths(mygraph, from = 1, to = 2)
igraph::walktrap.community(mygraph)
# Interactive view using visNetwork
if (requireNamespace("visNetwork", quietly = TRUE)) {
vgraph <- mygraph
igraph::V(vgraph)$shape <- rep("dot", length(igraph::V(vgraph)))
v <- visNetwork::visIgraph(vgraph)
mylayout <- as.matrix(v$x$nodes[, c("x", "y")])
mylayout[, 2] <- -mylayout[, 2]
plot(mygraph, layout = mylayout)
}
# Opening in Cytoscape using RCy3
if (requireNamespace("RCy3", quietly = TRUE)) {
# Make sure that Cytoscape is open before running the following line
# RCy3::createNetworkFromIgraph(mygraph)
}
# }
Run the code above in your browser using DataLab