-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSF 3 code.R
100 lines (75 loc) · 2.5 KB
/
SF 3 code.R
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
## umap customised final
### first image
library(umap)
library(tidyverse)
library(ggplot2)
library(dplyr)
### the last col has label, removing the label
rf = as.data.frame(tab_dfnew)
rf = na.omit(tab_dfnew)
rf = rf[,-1]
rf.data <- rf[,c(2:6)]
### scale if required
rf.data <- scale(rf.data)
## label vector
rf.labels <- rf[, "Label1"]
### applying uMAP transformation
rf.umap <- umap(rf.data)
### generating dataframe
rf.umap_df = as.data.frame(rf.umap$layout)
rf.umap_df = cbind(rf.umap_df,rf.labels)
colnames(rf.umap_df) = c("UMAP1","UMAP2","Label")
### another function that makes use of ggplot
p = rf.umap_df %>%
ggplot(aes(x = UMAP1,
y = UMAP2,
color = Label))+
geom_point(size = 1.1)+
labs(x = "UMAP1",
y = "UMAP2",
title = "UMAP plot Genomic Parameters ",
subtitle = "Taxon I")+
theme(title = element_text(hjust = 0.5,size = 10),
plot.subtitle = element_text(hjust = 0.5, size = 10),
legend.title = element_text(color = "black", size = 05.5),
legend.text = element_text(color = "black", size = 06.5,face = "italic"),
legend.position = "top",
axis.title = element_text(size = 10))
png(filename = "umap taxon I.png",res = 300, h=1500,w=1500)
print(p)
dev.off()
### 2nd figure
### the last col has label, removing the label
rf = as.data.frame(tab_dfnew)
rf = na.omit(tab_dfnew)
rf = rf[,-2]
rf.data <- rf[,c(2:6)]
### scale if required
rf.data <- scale(rf.data)
## label vector
rf.labels <- rf[, "Label2"]
### applying uMAP transformation
rf.umap <- umap(rf.data)
### generating dataframe
rf.umap_df = as.data.frame(rf.umap$layout)
rf.umap_df = cbind(rf.umap_df,rf.labels)
colnames(rf.umap_df) = c("UMAP1","UMAP2","Label")
### another function that makes use of ggplot
p = rf.umap_df %>%
ggplot(aes(x = UMAP1,
y = UMAP2,
color = Label))+
geom_point(size = 1.1)+
labs(x = "UMAP1",
y = "UMAP2",
title = "UMAP plot Genomic Parameters ",
subtitle = "Taxon II")+
theme(title = element_text(hjust = 0.5,size = 10),
plot.subtitle = element_text(hjust = 0.5, size = 10),
legend.title = element_text(color = "black", size = 05.5),
legend.text = element_text(color = "black", size = 06.5,face = "italic"),
legend.position = "top",
axis.title = element_text(size = 10))
png(filename = "umap taxon II.png",res = 300, h=1500,w=1500)
print(p)
dev.off()