Vertex, Edge and Graph Attributes
Equipping a graph with attributes is referred to as decorating the graph. Typically, the vertices or edges of a graph (or both) are decorated with attributes, although the graph as a whole may be decorated as well. In igraph, the elements of graph objects (i.e., particularly the vertex and edge sequences, and subsets thereof) may be equipped with attributes simply by using the ‘$’ operator.
For example,
V(dg)$name
For example,
V(dg)$name
Edge attributes similarly are values of variables indexed by adjacent vertex pairs. A graph for which the edges are equipped with weights is referred to as a weighted graph.
For example,
is.weighted(g)
wg <- g
E(wg)$weight <- runif(ecount(wg))
is.weighted(wg)
In principle, a graph itself may be decorated with an attribute, and indeed, it is possible to equip graph objects with attributes in igraph. The most natural use of this feature arguably is to equip a graph with relevant background information, such as a name.
For example,
g$name <- "Toy Graph
Using Data Frames
In R, a network graph and all vertex and edge attributes can be conveniently represented using two data frames, one with vertex information, and the other, with edge information. Under this approach, the first column of the vertex data frame contains the vertex names (i.e., either the default numerical labels or symbolic), while each of the other columns contain the values of a given vertex attribute. Similarly, the first two columns of the edge data frame contain an edge list defining the graph, while each of the other columns contain the values of a given edge attribute.
For example,
list.vertex.attributes(g)
(in addition to the vertex name)
Using Data Frames
In R, a network graph and all vertex and edge attributes can be conveniently represented using two data frames, one with vertex information, and the other, with edge information. Under this approach, the first column of the vertex data frame contains the vertex names (i.e., either the default numerical labels or symbolic), while each of the other columns contain the values of a given vertex attribute. Similarly, the first two columns of the edge data frame contain an edge list defining the graph, while each of the other columns contain the values of a given edge attribute.
For example,
list.vertex.attributes(g)
(in addition to the vertex name)
No comments:
Post a Comment