generate.complete.graph | R Documentation |
This function generates a complete graph. Where each node represents a object_i and the edges have a cost representing the distance d_ij between object_i and other object_j.
generate.complete.graph(nodes.list, distance.matrix)
nodes.list |
A vector with a subset of nodes (objects) of the data matrix for which the complete graph must be generated. |
distance.matrix |
A distance matrix between each pair of objects in |
edges.complete.graph |
A object of class "data.frame" with three columns (object_i, object_j, d_ij) representing the distance between object i and object j of the distance matrix. For instance: |
object_i | object_j | d_ij |
1 | 2 | 1.60 |
1 | 3 | 0.08 |
1 | 4 | 1.21 |
... | ... | ... |
n-1 | n | ... |
Mario Inostroza-Ponta, Jorge Parraga-Alava, Pablo Moscato
set.seed(1987) ##Generates a data matrix of dimension 50X13 n=50; m=13 x <- matrix(runif(n*m, min = -5, max = 10), nrow=n, ncol=m) ##Computes a distance matrix of x. library("stats") d <- base::as.matrix(stats::dist(x, method="euclidean")) ##Generates complete graph (CG) cg <- generate.complete.graph(1:nrow(x),d) head(cg) ##Visualizing CG graph library("igraph") cg.network=igraph::graph.adjacency(d, mode="undirected", weighted=TRUE) plot(cg.network, edge.label=round(E(cg.network)$weight, 2), main="Complete Graph")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.