## generate a random DAG:
p <- 10
set.seed(45)
myDAG <- randomDAG(p, prob = 0.3)
if(requireNamespace("Rgraphviz")) {
## plot whole the DAG
plot(myDAG, main = "randomDAG(10, prob = 0.3)")
op <- par(mfrow = c(3,2))
## plot the neighbours of node number 8 up to distance 1
plotSG(myDAG, 8, 1, directed = TRUE)
plotSG(myDAG, 8, 1, directed = FALSE)
## plot the neighbours of node number 8 up to distance 2
plotSG(myDAG, 8, 2, directed = TRUE)
plotSG(myDAG, 8, 2, directed = FALSE)
## plot the neighbours of node number 8 up to distance 3
plotSG(myDAG, 8, 3, directed = TRUE)
plotSG(myDAG, 8, 3, directed = FALSE)
## Note that the layout of the subgraph might be different than in the
## original graph, but the graph structure is identical
par(op)
} else { ## without 'Rgraphviz'
sg2d <- plotSG(myDAG, 8, 2, directed = TRUE, plot=FALSE)
sg2u <- plotSG(myDAG, 8, 2, directed = FALSE, plot=FALSE)
}
Run the code above in your browser using DataLab