do.optimGraphviz: Optimize the Dimensional Anchors Position using the Graphviz...

View source: R/do.optimGraphviz.R

do.optimGraphvizR Documentation

Optimize the Dimensional Anchors Position using the Graphviz algorithm

Description

Allows to compute the best arrangement of Dimensional Anchors so that visualization efficiency (i.e. maintaining graph structure) is optimized. The Graphviz algorithm is implemented in C++ for optimal computational efficiency.

Usage

do.optimGraphviz(
  x,
  graph,
  attractG = 1,
  repelG = 1,
  law = 0,
  steps = 10,
  springs = NULL,
  weight = "weight"
)

Arguments

x

a data.frame or matrix to be projected, with column names matching row names in springs

graph

igraph object

attractG

Number specifying the weight of the attractive forces

repelG

Number specifying the weight of the repulsive forces

law

Integer, specifying how forces change with distance: 0 = (inverse) linear, 1 = (inverse) square

steps

Number of iterations of the algorithm before re-considering convergence criterion

springs

Numeric matrix with initial anchor coordinates. When NULL (=default), springs are initialized by make.S

weight

the name of the attribute containing the edge weights to use for optimization

Details

Graphviz is a variant of Freeviz (do.optimFreeviz, applicable to a dataset for which a graph structure (i.e. igraph object) is available. Attractive forces are defined between connected nodes in the graph, and repulsive forces between all non-connected nodes. To better maintain the original graph structure after projection, spring constants between connected nodes are proportional to their edge weights. Graphviz can be used as an alternative to Freeviz when class labels are not available.

Value

A matrix with 2 columns (x and y coordinates of dimensional anchors) and 1 line per dimensional anchor (so called springs).

Author(s)

Nicolas Sauwen

Examples

data(iris)
das <- c('Sepal.Length','Sepal.Width','Petal.Length','Petal.Width')
S <- make.S(das)
rv <- do.radviz(iris,S)

plot(rv,anchors.only=FALSE)

## compute distance matrix
d.iris <- dist(iris[,das])

## define a kNN matrix
n.iris <- as.matrix(d.iris)
n.iris <- apply(n.iris,1,function(x,k=12) {
  x[order(x)>(k+1)] <- 0
  return(x)
})
diag(n.iris) <- 0

## compute weights for kNN matrix
w.iris <- n.iris
w.iris <- exp(-w.iris^2/(2*median(w.iris[w.iris!=0])^2))
w.iris[n.iris==0] <- 0

## create graph
library(igraph)
g.iris <- graph.adjacency(w.iris,mode='undirected',weight=TRUE,diag=FALSE)

V(g.iris)$Species <- as.character(iris[,'Species'])
V(g.iris)$color <- as.numeric(iris[,'Species'])

plot(g.iris,
     vertex.label=NA)

## project using Radviz
new.S <- do.optimGraphviz(iris[,das],
                          g.iris)

grv <- do.radviz(iris[,das],
                new.S,
                graph=g.iris)

library(ggplot2)
plot(grv)+
  geom_point(aes(color=iris[,'Species']))

yannabraham/Radviz documentation built on April 3, 2022, 1:30 p.m.