|
a |
|
b/R/DIscBIO-generic-plottSNE.R |
|
|
1 |
#' @title tSNE map |
|
|
2 |
#' @description Visualizing the k-means or model-based clusters using tSNE maps |
|
|
3 |
#' @param object \code{DISCBIO} class object. |
|
|
4 |
#' @importFrom graphics text |
|
|
5 |
#' @return A plot of t-SNEs. |
|
|
6 |
setGeneric("plottSNE", function(object) { |
|
|
7 |
standardGeneric("plottSNE") |
|
|
8 |
}) |
|
|
9 |
|
|
|
10 |
#' @rdname plottSNE |
|
|
11 |
#' @export |
|
|
12 |
setMethod( |
|
|
13 |
"plottSNE", |
|
|
14 |
signature = "DISCBIO", |
|
|
15 |
definition = function(object) { |
|
|
16 |
# ====================================================================== |
|
|
17 |
# Validating |
|
|
18 |
# ====================================================================== |
|
|
19 |
ran_k <- length(object@tsne) > 0 |
|
|
20 |
ran_m <- length(object@MBtsne) > 0 |
|
|
21 |
if (ran_k) { |
|
|
22 |
part <- object@kmeans$kpart |
|
|
23 |
x <- object@tsne |
|
|
24 |
} else if (ran_m) { |
|
|
25 |
part <- object@MBclusters$clusterid |
|
|
26 |
x <- object@MBtsne |
|
|
27 |
} else { |
|
|
28 |
stop("run comptsne before plottSNE") |
|
|
29 |
} |
|
|
30 |
# ====================================================================== |
|
|
31 |
# Plotting |
|
|
32 |
# ====================================================================== |
|
|
33 |
col <- c("black", "blue", "green", "red", "yellow", "gray") |
|
|
34 |
LEN <- length(levels(factor(part))) |
|
|
35 |
plot( |
|
|
36 |
x, |
|
|
37 |
las = 1, |
|
|
38 |
xlab = "Dim 1", |
|
|
39 |
ylab = "Dim 2", |
|
|
40 |
pch = 20, |
|
|
41 |
cex = 1.5, |
|
|
42 |
col = "lightgrey" |
|
|
43 |
) |
|
|
44 |
for (i in seq_len(LEN)) { |
|
|
45 |
if (sum(part == i) > 0) { |
|
|
46 |
text( |
|
|
47 |
x[part == i, 1], |
|
|
48 |
x[part == i, 2], |
|
|
49 |
i, |
|
|
50 |
col = col[i], |
|
|
51 |
cex = .75, |
|
|
52 |
font = 4 |
|
|
53 |
) |
|
|
54 |
} |
|
|
55 |
} |
|
|
56 |
} |
|
|
57 |
) |