-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTSNE.R
More file actions
64 lines (56 loc) · 1.45 KB
/
TSNE.R
File metadata and controls
64 lines (56 loc) · 1.45 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
# Refer: https://statkclee.github.io/model/model-tsne.html
library(tidyverse)
library(Rtsne)
library(tools)
base_Dir <- 'D:/GST.Results/Inference/GST/'
list.files(base_Dir)
for(file in list.files(base_Dir))
{
if (toupper(file_ext(file)) != 'TXT')
{
next
}
else if (file.exists(sprintf('%s%s', base_Dir, str_replace(file, '.TXT', '.PNG'))))
{
next
}
gst.Data <- read_delim(
sprintf('%s%s', base_Dir, file),
"\t",
escape_double = FALSE,
locale = locale(encoding = "UTF-8"),
trim_ws = TRUE
)
gst.TSNE <- Rtsne(
gst.Data[,c(-1)],
PCA = TRUE,
check_duplicates = FALSE,
dims = 2,
max_iter = 1000,
perplexity= 5
)
gst.TSNE.DF <- data.frame(
TSNE_x = gst.TSNE$Y[, 1],
TSNE_y = gst.TSNE$Y[, 2],
Data_Tag = gst.Data$Tag
)
plot <- ggplot(data= gst.TSNE.DF, aes(x= TSNE_x, y= TSNE_y, color= Data_Tag)) +
geom_point() +
#geom_text(aes(label= Data_Tag)) +
labs(title= 'GST t-SNE', x= '', y= '') +
theme_bw() +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
# axis.text = element_blank(),
strip.text = element_text(size = 20),
panel.grid=element_blank(),
legend.position = 'right',
plot.title = element_text(hjust = 0.5)
)
ggsave(
filename = sprintf('%s%s', base_Dir, str_replace(file, '.TXT', '.PNG')),
plot = plot,
device = "png", width = 12, height = 10, units = "cm", dpi = 300
)
}