Created
June 22, 2018 02:27
-
-
Save chasemc/7f0ebd664de3591f3b112cc047414aa9 to your computer and use it in GitHub Desktop.
Messy tSNE code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spongeSmallIn <- readRDS("data/spongeSmall.rds") | |
spongeSmall <- MALDIquant::intensityMatrix(spongeSmallIn) | |
spongeSmall[is.na(spongeSmall)] <- 0.000000001 | |
spongeSmall <- prcomp(log10(spongeSmall)) | |
spongeSmall <- spongeSmall$x[,1:50] | |
z <- sapply(spongeSmallIn, function(x) x@metaData$Strain ) | |
q <- as.data.frame(spongeSmall) | |
rownames(q) <- z | |
z1 <- Rtsne::Rtsne(q, pca=FALSE, dims=3, perplexity = 10, theta = 0, max_iter = 1000,check_duplicates=FALSE) | |
d <-z1 | |
d <- as.data.frame(d$Y) | |
colnames(d) <- c("Dim.1","Dim.2","Dim.3") | |
d <- as.data.frame(d) | |
pcaDat <- d | |
plot(pcaDat[,1:2]) | |
mydata <- pcaDat | |
wss <- (nrow(mydata)-1)*sum(apply(mydata,2,var)) | |
for (i in 2:15) wss[i] <- sum(kmeans(mydata, | |
centers=i)$withinss) | |
plot(1:15, wss, type="b", xlab="Number of Clusters", | |
ylab="Within groups sum of squares") | |
a <- kmeans(pcaDat, 12) | |
b <- RColorBrewer::brewer.pal(12, "Paired") | |
pp <- bind_cols(pcaDat, k=as.factor(a$cluster)) | |
colnames(pp) <- c("a1", "b1", "c1", "d1") | |
pp <- as_tibble(pp) | |
plotly::plot_ly(data=pp,x= ~a1, y= ~b1, z = ~c1, | |
type="scatter3d",mode="markers",hoverinfo = 'text',text=rownames(q), color = ~d1, colors = b) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment