# Notable graphs # make_graph can create some notable graphs. The name of the graph (case insensitive), a character scalar must be suppliced as the edges argument, and other arguments are ignored. (A warning is given is they are specified.) # eg. # Cubical # The Platonic graph of the cube. A convex regular polyhedron with 8 vertices and 12 edges. g <- make_graph("Cubical")%>% set_vertex_attr("name",value =LETTERS[1:4])
library(igraphdata) ### data:Loads specified data sets, or list the available data sets. data(package="igraphdata") # Data sets in package ‘igraphdata’: # # Koenigsberg Bridges of Koenigsberg from Euler's times # UKfaculty Friendship network of a UK university faculty # USairports US airport network, 2010 December # enron Enron Email Network # foodwebs A collection of food webs # immuno Immunoglobulin interaction network # karate Zachary's karate club network # kite Krackhardt's kite # macaque Visuotactile brain areas and connections # rfid Hospital encounter network data # yeast Yeast protein interaction network
This is the standard way of showing (printing) an igraph graph object on the screen. The top line of the output declares that the object is an igraph graph, and also lists its most important properties. A four-character long code is printed first:
‘D/U’ The first character is either ‘D’ or ‘U’ and encodes whether the graph is directed or undireted. ‘N’ The second letter is ‘N’ for named graphs (see Section 1.2.5). A dash here means that the graph is not named. ‘W’ The third letter is ‘W’ if the graph is weighted (in other words, if the graph is a valued graph, Section 2.4). Unweighted graphs have a dash in this position. ‘B’ Finally, the fourth is ‘B’ if the graph is bipartite (two-mode, Section ??). For unipartite (one-mode) graphs a dash is printed here.
This notation might seem quite dense at first, but it is easy to get used to and conveys much information in a small space. Then two numbers are printed, these are the number of vertices and the number of edges in the graph, 45 and 463 in our case. At the end of the line the name of the graph is printed, if there is any. The next line(s) list attributes, meta-data that belong to the vertices, edges or the graph itself. Finally, the edges of the graph are listed. Except for very small graphs, this list is truncated, so that it fits to the screen.
data("kite") V(kite) # + 10/10 vertices, named, from 6b7ddad: # [1] A B C D E F G H I J V(kite)[1:3,7:10] # + 7/10 vertices, named, from 6b7ddad: # [1] A B C G H I J V(kite)[degree(kite)<2] # + 1/10 vertex, named, from 6b7ddad: # [1] J V(kite)[.nei("D")] # + 6/10 vertices, named, from 6b7ddad: # [1] A B C E F G V(kite)[.innei("D")] # + 6/10 vertices, named, from 6b7ddad: # [1] A B C E F G V(kite)[.outnei("D")] # + 6/10 vertices, named, from 6b7ddad: # [1] A B C E F G V(kite)[.inc("A|D")] # + 2/10 vertices, named, from 6b7ddad: # [1] A D c(V(kite)["A"],V(kite)["D"]) # + 2/10 vertices, named, from 6b7ddad: # [1] A D rev(V(kite)) # + 10/10 vertices, named, from 6b7ddad: # [1] J I H G F E D C B A unique(V(kite)["A","A","C","C"]) # + 2/10 vertices, named, from 6b7ddad: # [1] A C
### Set operation
union(V(kite)[1:5],v(kite)[6:10]) # + 2/10 vertices, named, from 6b7ddad: # [1] A C intersection(V(kite)[1:7],V(kite)[5:10]) # + 3/10 vertices, named, from 6b7ddad: # [1] E F G difference(V(kite),V(kite)[1:5]) # + 5/10 vertices, named, from 6b7ddad: # [1] F G H I J