Created
March 14, 2018 16:46
-
-
Save diazdc/bfdd7f2d11841d65d62a76bf803181f5 to your computer and use it in GitHub Desktop.
3D Plot for Seurat
This file contains 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
counts.seurat <- RunTSNE(counts.seurat, | |
reduction.use = "pca", | |
dims.use = 1:6, | |
dim.embed = 3) | |
DimPlot(object = counts.seurat, reduction.use = "tsne", dim.1 = 1, dim.2 = 3) | |
tSNE_1 <- counts.seurat@dr$tsne@cell.embeddings[,1] | |
tSNE_2 <- counts.seurat@dr$tsne@cell.embeddings[,2] | |
tSNE_3 <- counts.seurat@dr$tsne@cell.embeddings[,3] | |
TSNEPlot(counts.seurat) | |
color_scheme <- as.numeric(1:14)[counts.seurat@ident] | |
for(i in 1:1521){ | |
if(color_scheme[i] == 1){ | |
color_scheme[i] <- "#F8766D" | |
}else if(color_scheme[i] == 2){ | |
color_scheme[i] <- "#E38900" | |
}else if(color_scheme[i] == 3){ | |
color_scheme[i] <- "#C49A00" | |
}else if(color_scheme[i] == 4){ | |
color_scheme[i] <- "#99A800" | |
}else if(color_scheme[i] == 5){ | |
color_scheme[i] <- "#53B400" | |
}else if(color_scheme[i] == 6){ | |
color_scheme[i] <- "#00BC56" | |
}else if(color_scheme[i] == 7){ | |
color_scheme[i] <- "#00C094" | |
}else if(color_scheme[i] == 8){ | |
color_scheme[i] <- "#00BFC4" | |
}else if(color_scheme[i] == 9){ | |
color_scheme[i] <- "#00B6EB" | |
}else if(color_scheme[i] == 10){ | |
color_scheme[i] <- "#06A4FF" | |
}else if(color_scheme[i] == 11){ | |
color_scheme[i] <- "#A58AFF" | |
}else if(color_scheme[i] == 12){ | |
color_scheme[i] <- "#DF70F8" | |
}else if(color_scheme[i] == 13){ | |
color_scheme[i] <- "#FB61D7" | |
}else if(color_scheme[i] == 14){ | |
color_scheme[i] <- "#FF66A8" | |
}else{NULL} | |
} | |
library(rgl) | |
plot3d(x = tSNE_1, y = tSNE_2, z = tSNE_3, | |
col = color_scheme, | |
type = "s", size = 0.3, box = FALSE) | |
rgl::rglwidget("~/Desktop/tSNE_3dplot.html") #save as html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool! I finally did it in this way,
gecko252com<- RunTSNE(combined, reduction.use = "tsne", dims.use = 1:6, dim.embed = 3)
DimPlot(object = combined, reduction.use = "tsne", dim.1 = 1, dim.2 = 3)
tSNE_1 <- combined[["tsne"]]@cell.embeddings[,1]
tSNE_2 <- combined[["tsne"]]@cell.embeddings[,2]
tSNE_3 <- combined[["tsne"]]@cell.embeddings[,3]
combined<- SetIdent(object = combined, cells = WhichCells(combined, expression = PITX2>1), value = '1')
combined <- SetIdent(object = combined, cells = WhichCells(combined, expression = PITX2<=1), value = '2')
TSNEPlot(combined)
levels(gecko252com)
Idents(gecko252com)
color_scheme <- as.numeric(1:2)[Idents(combined)]
for(i in 1:2){
if(color_scheme[i] == 1){
color_scheme[i] <- "#F8766D"
}else if(color_scheme[i] == 2){
color_scheme[i] <- "#E38900"
}else{NULL}
}
library(rgl)
open3d()
plot3d(x = tSNE_1, y = tSNE_2, z = tSNE_3,
col = color_scheme,
type = "s", size = 0.3, box = FALSE)
M <- par3d("userMatrix")
if (!rgl.useNULL())
play3d( par3dinterp(time = (0:2)*0.75, userMatrix = list(M,
rotate3d(M, pi/2, 1, 0, 0),
rotate3d(M, pi/2, 0, 1, 0) ) ),
duration = 3 )
movie3d( spin3d(), duration = 5, dir = "C:/Users/ideapad 710s plus i7/Desktop/courses")