-
Notifications
You must be signed in to change notification settings - Fork 5
/
DIscBIO-generic-plotSymbolstSNE.R
58 lines (56 loc) · 1.66 KB
/
DIscBIO-generic-plotSymbolstSNE.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
#' @title tSNE map for K-means clustering with symbols
#' @description Visualizing the K-means clusters using tSNE maps
#' @param object \code{DISCBIO} class object.
#' @param types If types=NULL then the names of the cells will be grouped
#' automatically. Default is NULL
#' @param legloc A keyword from the list "bottomright", "bottom", "bottomleft",
#' "left", "topleft", "top", "topright", "right" and "center". Default is
#' "bottomright"
setGeneric(
"plotSymbolstSNE",
function(object, types = NULL, legloc = "bottomright") {
standardGeneric("plotSymbolstSNE")
}
)
#' @export
#' @return Plot of tsne objet slot, grouped by gene.
#' @rdname plotSymbolstSNE
setMethod(
"plotSymbolstSNE",
signature = "DISCBIO",
definition = function(object, types, legloc = "bottomright") {
if (is.null(types)) {
types <- names(object@fdata)
}
if (length(object@tsne) == 0) {
stop("run comptsne before plotSymbolstSNE")
}
if (length(types) != ncol(object@fdata)) {
stop(
"types argument has wrong length.",
"Length has to equal to the column number of object@ndata"
)
}
coloc <- rainbow(length(unique(types)))
syms <- vector()
plot(
object@tsne,
xlab = "Dim 1",
ylab = "Dim 2",
pch = 20,
col = "grey"
)
for (i in seq_len(length(unique(types)))) {
f <- types == sort(unique(types))[i]
syms <- append(syms, ((i - 1) %% 25) + 1)
points(
object@tsne[f, 1],
object@tsne[f, 2],
col = coloc[i],
pch = ((i - 1) %% 25) + 1,
cex = 1
)
}
legend(legloc, legend = sort(unique(types)), col = coloc, pch = syms)
}
)