Multidimensional Scaling (MDS)
This page shows Multidimensional Scaling (MDS) with R. It demonstrates with an example of automatic layout of Australian cities based on distances between them. The layout obtained with MDS is very close to their locations on a map.
At first, the data of distances between 8 city in Australia are loaded from http://rosetta.reltech.org/TC/v15/Mapping/data/dist-Aus.csv.
Alternatively, we can download the file first and then read it into R from local drive.
Then we remove the frist column, acronyms of cities, and set them to row names.
After that, we run Multidimensional Scaling (MDS) with function cmdscale(), and get x and y coordinates. k is the maximum dimension of space that the data are to be represented in, and eig indicates whether eigenvalues should be returned.
Then we visualise the result, which shows the positions of cities are very close to their relative locations on a map.
By flipping both x- and y-axis, Darwin and Brisbane are moved to the top (north), which makes it easier to compare with a map.
MDS is also implemented in the igraph package as layout.mds. Below we creae an 8-node graph and set its layout with the above distance matrix. It also shows a layout very close to that on a map.