# Displaying High-Dimensional Data in R # # Get the Iris dataset # Data <- iris # 3x50 irises, 4 variables plus iris species str(Data) summary(Data) # Data <- na.omit(Data) # Gcol <- as.numeric(Data[ ,5]) # # Remove "species" from the data # IRIS <- Data[ ,-5] # ## install.packages("FactoMineR") ## install.packages("factoextra") # library(FactoMineR) library(factoextra) # IRIS_PCA <- prcomp(IRIS) # # Plot variables in the PCA space # plot(IRIS_PCA$x[ ,1:2], col=Gcol, pch=16) # # # PCA plot of iris data colored by species with ellipses added # iris.pca <- PCA(iris[,-5], graph = FALSE) fviz_pca_ind(iris.pca, geom.ind = "point", # show points only (nbut not "text") col.ind = iris$Species, # color by groups palette = c("#00AFBB", "#E7B800", "#FC4E07"), addEllipses = TRUE, # Concentration ellipses legend.title = "Groups" ) # # Sammon's nonlinear mapping # ## install.packages("MASS") ## install.packages("magrittr") ## install.packages("dplyr") ## install.packages("ggpubr") library(MASS) library(magrittr) library(dplyr) library(ggpubr) # IRIS2 <- IRIS IRIS2[143,2] <- IRIS2[143,2] + 0.05 # Dist_IRIS2 <- dist(IRIS2) mds_SAM <- sammon(Dist_IRIS2, niter=1000) plot(mds_SAM$points, pch=16, col=Gcol, main="Sammon map") # # Kruskal nonlinear mapping # mds_KR <- isoMDS(Dist_IRIS2, maxit=1000) plot(mds_KR$points, pch=16, col=Gcol, main="Kruskal map") # # t-SNE # ## install.packages("tsne") library(tsne) IRIS_tsne <- tsne(IRIS, initial_dims = 2) IRIS_tsne <- data.frame(IRIS_tsne) attributes(IRIS_tsne) # plot(IRIS_tsne$X1, IRIS_tsne$X2, col=Gcol, pch=16) # # Another t-SNE test # IRIS_tsne <- tsne(IRIS, initial_dims=3, max_iter = 2000, perplexity=30) IRIS_tsne <- data.frame(IRIS_tsne) plot(IRIS_tsne$X1, IRIS_tsne$X2, col=Gcol, pch=16) # # UMAP # ## install.packages("umap") library(umap) # IRIS.umap <- umap(IRIS, n_neighbors = 5) plot(IRIS.umap$layout, col=Gcol, pch=16) # x <- runif(50) IRIS.umap <- umap(IRIS, n_neighbors = 10) plot(IRIS.umap$layout, col=Gcol, pch=16) # x <- runif(50) IRIS.umap <- umap(IRIS, n_neighbors = 10) plot(IRIS.umap$layout, col=Gcol, pch=16) # x <- runif(50) IRIS.umap <- umap(IRIS, n_neighbors = 15) plot(IRIS.umap$layout, col=Gcol, pch=16) # # Parallel Coordinates # parcoord(IRIS, col = Gcol, var.label = TRUE, main = "iris dataset") #