-
Notifications
You must be signed in to change notification settings - Fork 5
/
DIscBIO-generic-plottSNE.R
57 lines (56 loc) · 1.48 KB
/
DIscBIO-generic-plottSNE.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
#' @title tSNE map
#' @description Visualizing the k-means or model-based clusters using tSNE maps
#' @param object \code{DISCBIO} class object.
#' @importFrom graphics text
#' @return A plot of t-SNEs.
setGeneric("plottSNE", function(object) {
standardGeneric("plottSNE")
})
#' @rdname plottSNE
#' @export
setMethod(
"plottSNE",
signature = "DISCBIO",
definition = function(object) {
# ======================================================================
# Validating
# ======================================================================
ran_k <- length(object@tsne) > 0
ran_m <- length(object@MBtsne) > 0
if (ran_k) {
part <- object@kmeans$kpart
x <- object@tsne
} else if (ran_m) {
part <- object@MBclusters$clusterid
x <- object@MBtsne
} else {
stop("run comptsne before plottSNE")
}
# ======================================================================
# Plotting
# ======================================================================
col <- c("black", "blue", "green", "red", "yellow", "gray")
LEN <- length(levels(factor(part)))
plot(
x,
las = 1,
xlab = "Dim 1",
ylab = "Dim 2",
pch = 20,
cex = 1.5,
col = "lightgrey"
)
for (i in seq_len(LEN)) {
if (sum(part == i) > 0) {
text(
x[part == i, 1],
x[part == i, 2],
i,
col = col[i],
cex = .75,
font = 4
)
}
}
}
)