[28e211]: / R / DIscBIO-generic-PCAplotSymbols.R

Download this file

58 lines (56 with data), 1.5 kB

 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 Plot PCA symbols
#' @description Generates a plot of grouped PCA components
#' @param object \code{DISCBIO} class object.
#' @param types If types=NULL then the names of the cells will be grouped
#' automatically. Default is NULL
#' @importFrom grDevices rainbow
#' @importFrom graphics legend
#' @return Plot of the Principal Components
#'
setGeneric("PCAplotSymbols", function(object, types = NULL) {
standardGeneric("PCAplotSymbols")
})
#' @export
#' @rdname PCAplotSymbols
setMethod(
"PCAplotSymbols",
signature = "DISCBIO",
definition = function(object, types = NULL) {
if (length(object@MBclusters) == 0) {
stop("run Exprmclust before PCAplotSymbols")
}
total <- object@MBclusters
types <- names(object@fdata)
types <- gsub("_[0-9]+", "", types)
coloc <- rainbow(length(unique(types)))
total <- object@MBclusters$pcareduceres
syms <- vector()
plot(
total[, 1],
total[, 2],
xlab = "PC1",
ylab = "PC2",
pch = 20,
cex = 0,
col = "grey",
las = 1
)
for (i in seq_len(length(unique(types)))) {
f <- types == sort(unique(types))[i]
syms <- append(syms, ((i - 1) %% 25) + 1)
points(
total[f, 1],
total[f, 2],
col = coloc[i],
pch = ((i - 1) %% 25) + 1,
cex = 1
)
}
legend(
"topright",
legend = sort(unique(types)),
col = coloc,
pch = syms
)
}
)