|
a |
|
b/R/DIscBIO-generic-plotSymbolstSNE.R |
|
|
1 |
#' @title tSNE map for K-means clustering with symbols |
|
|
2 |
#' @description Visualizing the K-means clusters using tSNE maps |
|
|
3 |
#' @param object \code{DISCBIO} class object. |
|
|
4 |
#' @param types If types=NULL then the names of the cells will be grouped |
|
|
5 |
#' automatically. Default is NULL |
|
|
6 |
#' @param legloc A keyword from the list "bottomright", "bottom", "bottomleft", |
|
|
7 |
#' "left", "topleft", "top", "topright", "right" and "center". Default is |
|
|
8 |
#' "bottomright" |
|
|
9 |
setGeneric( |
|
|
10 |
"plotSymbolstSNE", |
|
|
11 |
function(object, types = NULL, legloc = "bottomright") { |
|
|
12 |
standardGeneric("plotSymbolstSNE") |
|
|
13 |
} |
|
|
14 |
) |
|
|
15 |
|
|
|
16 |
#' @export |
|
|
17 |
#' @return Plot of tsne objet slot, grouped by gene. |
|
|
18 |
#' @rdname plotSymbolstSNE |
|
|
19 |
setMethod( |
|
|
20 |
"plotSymbolstSNE", |
|
|
21 |
signature = "DISCBIO", |
|
|
22 |
definition = function(object, types, legloc = "bottomright") { |
|
|
23 |
if (is.null(types)) { |
|
|
24 |
types <- names(object@fdata) |
|
|
25 |
} |
|
|
26 |
if (length(object@tsne) == 0) { |
|
|
27 |
stop("run comptsne before plotSymbolstSNE") |
|
|
28 |
} |
|
|
29 |
if (length(types) != ncol(object@fdata)) { |
|
|
30 |
stop( |
|
|
31 |
"types argument has wrong length.", |
|
|
32 |
"Length has to equal to the column number of object@ndata" |
|
|
33 |
) |
|
|
34 |
} |
|
|
35 |
|
|
|
36 |
coloc <- rainbow(length(unique(types))) |
|
|
37 |
syms <- vector() |
|
|
38 |
plot( |
|
|
39 |
object@tsne, |
|
|
40 |
xlab = "Dim 1", |
|
|
41 |
ylab = "Dim 2", |
|
|
42 |
pch = 20, |
|
|
43 |
col = "grey" |
|
|
44 |
) |
|
|
45 |
for (i in seq_len(length(unique(types)))) { |
|
|
46 |
f <- types == sort(unique(types))[i] |
|
|
47 |
syms <- append(syms, ((i - 1) %% 25) + 1) |
|
|
48 |
points( |
|
|
49 |
object@tsne[f, 1], |
|
|
50 |
object@tsne[f, 2], |
|
|
51 |
col = coloc[i], |
|
|
52 |
pch = ((i - 1) %% 25) + 1, |
|
|
53 |
cex = 1 |
|
|
54 |
) |
|
|
55 |
} |
|
|
56 |
legend(legloc, legend = sort(unique(types)), col = coloc, pch = syms) |
|
|
57 |
} |
|
|
58 |
) |