Draw graphs using R: (6 Easy steps)

Definition: Formally, a graph G = (V,E) is a mathematical structure consisting of a set V of vertices and a set of E of edges, where elements of E are unordered pairs {u,v} of distinct vertices.
These are the following steps by which you can draw a graph in R easily


1st step: Install the igraph using the following code
install.packages("igraph")


2nd step: Import the igraph package
library(igraph)


3rd step: Create a variable and assign graph.formula() object by the following way
g<-graph.formula(1-2,1-3,2-3,2-4,3-5,4-5,4-6,4-7,5-6,6-7)


4th step: You can see the vertices using this function
V(g)
Output:
+ 7/7 vertices, named, from e429581:
[1] 1 2 3 4 5 6 7


5th step: You can also see the edges using this function
E(g)
Output:
+ 10/10 edges from e429581 (vertex names):
 [1] 1--2 1--3 2--3 2--4 3--5 4--5 4--6 4--7 5--6 6--7


6th step: Now you can see the graph using plot() function
plot(g)
Output: