Visualize largest cliques
Often in network visualization you will need to subset part of a network to inspect the inter-connections of particular vertices. Here, you will create a visualization of the largest cliques in the Forrest Gump network. In the last exercise you determined that there were two cliques of size 9. You will plot these side-by-side after creating two new igraph objects by subsetting out these cliques from the main network. The function subgraph()
enables you to choose which vertices to keep in a new network object.
This exercise is part of the course
Network Analysis in R
Exercise instructions
- Assign the list of the largest cliques in the network to the object
lc
. - Create two new undirected subgraphs using the function
subgraph()
. The first,gs1
, should contain only the vertices in the first largest clique. The second,gs2
, should contain only the vertices in the second largest clique. This function is wrapped inas.undirected()
to ensure that the subgraph is also undirected. - Visualize the two largest cliques side by side using
plot()
. First execute the code:par(mfrow=c(1,2))
. This is to ensure that the two visualizations sit side-by-side. Make sure that the layout is set tolayout.circle()
to make the visualization easier to view.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(igraph)
# Assign largest cliques output to object 'lc'
lc <- ___(g)
# Create two new undirected subgraphs, each containing only the vertices of each largest clique.
gs1 <- as.undirected(___(g, ___[[1]]))
gs2 <- as.undirected(___(g, ___[[2]]))
# Plot the two largest cliques side-by-side
par(mfrow=c(1,2)) # To plot two plots side-by-side
___(gs1,
vertex.label.color = "black",
vertex.label.cex = 0.9,
vertex.size = 0,
edge.color = 'gray28',
main = "Largest Clique 1",
layout = ___(gs1)
)
___(gs2,
vertex.label.color = "black",
vertex.label.cex = 0.9,
vertex.size = 0,
edge.color = 'gray28',
main = "Largest Clique 2",
layout = ___(gs2)
)