t-sne code and labelling issue for rna seq data I'm trying to run t-sne on my coding as well as non coding genes. Even though I'm getting output I'm not confident about my code (The output it's difficult to interpret).

I have a data set of total 16 cell type and about 3000 genes.

This is how my data is first column is gene rest is sample:

gene    H1  H2  H3  H4  M2  M3  M4  C1  C2  C3  C4  G2  G3  G4  Gran1   Gran2


The code used:

library(Rtsne)
file1&lt;- read.csv('UNIQUE_WGCNA_FILE.csv',header = T,row.names = 1)
trn &lt;- data.matrix(file1)
dim(trn)

tsne &lt;- Rtsne(as.matrix(trn[,1:16]), check_duplicates = FALSE, pca = FALSE, perplexity=50, theta=0.5, dims=3)

cols &lt;- rainbow(10)
plot(tsne$Y, t='n')
text(tsne$Y, labels=as.numeric(trn[,1]), col=cols[trn[,1]])

require(rgl)
plot3d(tsne$Y, col=cols[trn[,1]])
legend3d("topright", legend = '0':'5', pch = 16, col = rainbow(10))
rgl.postscript("Merge.pdf", "pdf")


I'm getting output but I don't know how to label so its becoming difficult.
Any suggestion or help how to label would be appreciated.
Although a bit late, here is the solution for this:

1) Create color/column levels:

levels = unlist(lapply(colnames(trn[,1:16]), function(x)
    {

        if(x == "H1") return("H1")
        else if(x == "H2") return("H2")


}))


2) 

plot(tsne$Y, col=factor(levels))


This should color columns H1 and H2 differently

Edit:

This is a sample complete code:

library(Rtsne)
file1&lt;- read.csv('filename.csv',header = T, row.names=1)
trn &lt;- data.matrix(file1)
dim(trn)

tsne &lt;- Rtsne(as.matrix(trn[,1:16]), check_duplicates = FALSE, pca = FALSE, perplexity=5, theta=0.5, dims=3)

collevels = unlist(lapply(colnames(trn), function(x)
{
  if(grepl("H1",x))
    return("blue")
  else if(grepl("H2",x))
    return("red")

  # etc ... for all the columns you want to color
}
))

colorColumns = factor(collevels)
require(rgl)
plot3d(tsne$Y[,1], tsne$Y[,2], tsne$Y[,3], col=colorColumns)