Multidimensional Scaling Example

This document will showcase the basics of multidimensional scaling using the infamous iris dataset.

head(iris)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa

Load iris dataset

data("iris")
dim(iris)
## [1] 150   5

Create a matrix of the 4 features and a vector of labels

iris.meas <- iris[,1:4]
iris.labels <- c(rep("se", 50),rep("ve", 50),rep("vi", 50))

Get the distance between rows in the data and use cmdscale()

iris.mds <- cmdscale(dist(iris.meas))

Plot

plot(iris.mds, col = iris$Species, pch =19, cex = 3.5, ylab ="y", xlab="x", main ="2-D Representation of Iris Data")
text(iris.mds, labels = iris.labels, col="white", family="serif")