-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisualize_clusters_and_umap.R
61 lines (34 loc) · 1.06 KB
/
visualize_clusters_and_umap.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
library(data.table)
library(pheatmap)
data <- fread('data/drums_and_features.csv')
dm <- data.matrix(data)
wavnames <- colnames(dm)
drum.categories <- unlist(lapply(wavnames, function(x){substr(x,0,2)}))
d.anno <- data.frame(drum.categories)
row.names(d.anno) <- colnames(dm)
pheatmap(dm, annotation_col = d.anno)
my_heatmap
min(dm + 39, na.rm = TRUE)
#dmc <- dm[complete.cases(dm),]
dmcs <- (dm - mean(dm, na.rm = TRUE)) / sd(dm, na.rm = TRUE)
for(i in 1:ncol(dmcs)){
dmcs[is.na(dmcs[,i]), i] <- mean(dmcs[,i], na.rm = TRUE)
}
pheatmap(log(dmcs + 10))
for(i in 1:ncol(dm)){
dm[is.na(dm[,i]), i] <- mean(dm[,i], na.rm = TRUE)
}
dm[is.na(dm)] = 4
hist(dm)
dm2 <- dm
dm2[dm2 < -5] <- 0.0
hist(scale(dm2), breaks = 100)
sdm2 <- scale(dm2)
sdm2[sdm2 > 1.5] <- 1.5
sdm2[sdm2 < -1.5] <- -1.5
pheatmap(sdm2, annotation_col = d.anno)
library(umap)
umap.dm <- umap(t(sdm2))
umap.dm.2 <- umap(t(dm))
dt <- data.table(x = umap.dm$layout[,1], y = umap.dm$layout[,2], sample = drum.categories)
ggplot(dt) + geom_point(aes(x = x, y = y, color = sample)) + theme_bw()