-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptional_3d_plotting1.Rmd
More file actions
124 lines (103 loc) · 3.07 KB
/
Optional_3d_plotting1.Rmd
File metadata and controls
124 lines (103 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
title: "Practical: 3D plotting"
subtitle: "Transcriptome Analysis Workshop"
author: "Adam Cribbs"
date: "24/01/2022"
output:
html_document:
theme: cosmo
toc: yes
---
```{r, out.width = "40%", echo=FALSE}
htmltools::img(src = knitr::image_uri(file.path("logo.png")),
alt = 'logo',
style = 'position:absolute; top:0; right:0; padding:10px;',
width='300')
```
This is optional for the workshop but I found the code within this repo very interesting: https://github.com/Dragonmasterx87/Interactive-3D-Plotting-in-Seurat-3.0.0. The code allows you to make 3D rendered plots for visualisation.
```{r}
#Install packages and dependencies
#install.packages('scatterplot3d')
#install.packages('rgl')
#install.packages('rmarkdown')
#install.packages('magick')
# Load packages
library(magick)
library(rmarkdown)
library(rgl) #interactive 3d plotting
library(Seurat)
```
# Make TSNE
Run a TSNE to 3 embeddings
```{r}
yourseuratobject <- readRDS("seurat_object.rds")
yourseuratobject <- RunTSNE(yourseuratobject,
reduction.use = "pca",
dims.use = 1:10,
dim.embed = 3)
tsne_1 <- yourseuratobject[["tsne"]]@cell.embeddings[,1]
tsne_2 <- yourseuratobject[["tsne"]]@cell.embeddings[,2]
tsne_3 <- yourseuratobject[["tsne"]]@cell.embeddings[,3]
#yourseuratobject <- RunUMAP(yourseuratobject,
# reduction = "pca", dims = 1:10, n.components = 3)
```
# TSNE plot
```{r}
TSNEPlot(yourseuratobject, label = FALSE,
cols = c("lightseagreen",
"gray50",
"darkgreen",
"red4",
"red",
"turquoise4",
"black",
"yellow4",
"royalblue1",
"lightcyan3",
"peachpuff3",
"khaki3",
"gray20",
"orange2",
"royalblue4",
"yellow3",
"gray80",
"darkorchid1",
"lawngreen",
"plum2",
"darkmagenta"),
pt.size = 2)
```
# Feature plot
```{r}
FeaturePlot(object = yourseuratobject, features = c("PECAM1"), min.cutoff =0, max.cutoff = 1, label = FALSE,
cols = c("grey", "red"), pt.size = 2)
```
# 3D plotting
```{r}
plot3d(x = tsne_1, y = tsne_2, z = tsne_3,
col = c("lightseagreen",
"gray50",
"darkgreen",
"red4",
"red",
"turquoise4",
"black",
"yellow4",
"royalblue1",
"lightcyan3",
"peachpuff3",
"khaki3",
"gray20",
"orange2",
"royalblue4",
"yellow3",
"gray80",
"darkorchid1",
"lawngreen",
"plum2",
"darkmagenta")[yourseuratobject@active.ident],
type = "s",
size = 0.5,
box = FALSE)
rgl::rglwidget() #save as html
```