if (!"FactoMineR" %in% installed.packages()) install.packages("FactoMineR") if (!"smacof" %in% installed.packages()) install.packages("smacof") if (!"vegan" %in% installed.packages()) install.packages("vegan") if (!"Rtsne" %in% installed.packages()) install.packages("Rtsne") #--------------------------------------------------------------------- # Data download pot = read.table("https://perso.univ-rennes1.fr/bernard.delyon/data/poterie.dat",header=TRUE) Four = pot$FOUR pot = pot[,1:9] #--------------------------------------------------------------------- # Compute PCA library(FactoMineR) pca = PCA(pot,ncp=2) # standardization and plots are by default dev.new() # open a new figure plot(pca$ind$coord,col="white",pch=20,xlab="PC1",ylab="PC2") text(pca$ind$coord,label=Four,col=Four) title("PCA") #--------------------------------------------------------------------- # Compute MDS D = dist(scale(pot)) # euclidean distance mds = cmdscale(D,k=2) dev.new() # open a new figure plot(mds,col="white",pch=20,xlab="1st axis",ylab="2nd axis") text(mds,label=Four,col=Four) title("MDS") library(smacof) mds.smacof <- mds(D) plot(mds.smacof, type = "p", label.conf = list(label = TRUE, col = "darkgray"), pch = 25, col = Four) #--------------------------------------------------------------------- # Compute isomap library(vegan) D = dist(scale(pot)) # euclidean distance isom = isomap(D, ndim=2,k=10) dev.new() # open a new figure plot(isom$points,col="white",pch=20,xlab="1st axis",ylab="2nd axis") text(isom$points,label=Four,col=Four) title("Isomap") #--------------------------------------------------------------------- # Compute tSNE library(Rtsne) perplexity = c(1,2,5,10) set.seed(9) dev.new() par(mfrow=c(1,4)) for (perp in perplexity){ tsne_model_1 = Rtsne(scale(pot), check_duplicates=FALSE, pca=TRUE, perplexity=perp, theta=0, dims=2) plot(tsne_model_1$Y,col=Four,pch=20,xlab="1st axis",ylab="2nd axis") title(perp) }