Identifying edges for each vertex
In this exercise you will learn how to identify particular edges. You will learn how to determine if an edge exists between two vertices as well as finding all vertices connected in either direction to a given vertex.
This exercise is part of the course
Network Analysis in R
Exercise instructions
- First make a visualization of this network using
plot()
. You will improve this visualization later. It can be useful to visualize the network before analysis. To improve visibility of the plot of this network, you should make the vertex size equal to0
and the edge arrow size equal to0.1
. - Check if there is an edge going in each direction between vertex 184 to vertex 178 using single brackets subsetting of the graph object. If a 1 is returned that indicates
TRUE
there is an edge. If a 0 is returned that indicatesFALSE
there is not an edge. - Using the function
incident()
identify those edges that go in either direction from vertex 184 or only those going out from vertex 184. The first argument should be the graph object, the second should be the vertex to examine and the third argument themode
indicating the direction. Choose fromall
,in
andout
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(igraph)
# Make a basic plot
___(g,
vertex.label.color = "black",
edge.color = 'gray77',
vertex.size = ___,
edge.arrow.size = ___,
layout = layout_nicely(g))
# Is there an edge going from vertex 184 to vertex 178?
g['___', '___']
# Is there an edge going from vertex 178 to vertex 184?
g['___', '___']
# Show all edges going to or from vertex 184
___(g, '___', mode = c("___"))
# Show all edges going out from vertex 184
___(g, '___', mode = c("___"))