normMDS | R Documentation |
A function to compare implied 2D topologies based on different distance matrices for the same data points
normMDS(dists, xy = NULL, id = "ID", ax = 1:2, chir = 3, x = "x", y = "y", ...)
dists |
A list (named, ideally) of distance matrices with the same points |
xy |
(Optional) The points in geographic space. This can be a
data.frame, data.table, SpatVect, or SpatialPointsDataFrame object. If provided,
axes orientations and chirality will be taken with respect to |
id |
Character. The name of the column in |
ax |
The index (if numeric) or Unique ID (if character) of the two points
defining the reference axis. The first point will be placed at the origin.
If |
chir |
The index (if numeric) or Unique ID (if character) of the point
defining the reference handendess/chirality. This must be a point not in |
x |
Character. The name of the column in |
y |
Character. The name of the column in |
... |
Additional parameters to pass to |
The function relies on isoMDS
from the MASS package to
generate pseudo-coordinates for distance matrices using a 2D non-metric
Multi Dimensional Scaling. Since the output orientation can be unpredictable,
normMDS aligns all topologies based on a common user-defined axis
(the ends of which will appear equidistant and equioriented on an output plot),
and selects a chiral reference point to ensure that plots are oriented in a
common orientation.
A named list, with each entry containing a data.table of estimated
pseudo-coordinates in (u,y) space. One unit is equal to the distance
between both points in the ax
parameter. If xy
was provided,
the first entry 'ref'
will be the geographic data.
# Create fake data
xy <- data.table(ID = c('A','B','C','D','E'),
x = runif(5, -100, 100),
y = runif(5, -100, 100))
# Calculate a distance matrix
dists <- as.matrix(stats::dist(xy[,.(x,y)], upper = TRUE, diag = TRUE) )
rownames(dists) <- xy$ID
colnames(dists) <- xy$ID
# Make a list of five fake distance matrices from five fake coordinates
dists <- list()
for (i in 1:5){
fake <- data.table(ID = c('A','B','C','D','E'),
x = runif(5, -100, 100),
y = runif(5, -100, 100))
fake <- as.matrix(stats::dist(fake[,.(x,y)], upper = TRUE, diag = TRUE) )
rownames(fake) <- xy$ID
colnames(fake) <- xy$ID
dists[[i]] <- fake
}
# Get pseudo-coordinates
normMDS(dists, xy = xy)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.