|
a |
|
b/R/DIscBIO-generic-PCAplotSymbols.R |
|
|
1 |
#' @title Plot PCA symbols |
|
|
2 |
#' @description Generates a plot of grouped PCA components |
|
|
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 |
#' @importFrom grDevices rainbow |
|
|
7 |
#' @importFrom graphics legend |
|
|
8 |
#' @return Plot of the Principal Components |
|
|
9 |
#' |
|
|
10 |
setGeneric("PCAplotSymbols", function(object, types = NULL) { |
|
|
11 |
standardGeneric("PCAplotSymbols") |
|
|
12 |
}) |
|
|
13 |
|
|
|
14 |
#' @export |
|
|
15 |
#' @rdname PCAplotSymbols |
|
|
16 |
setMethod( |
|
|
17 |
"PCAplotSymbols", |
|
|
18 |
signature = "DISCBIO", |
|
|
19 |
definition = function(object, types = NULL) { |
|
|
20 |
if (length(object@MBclusters) == 0) { |
|
|
21 |
stop("run Exprmclust before PCAplotSymbols") |
|
|
22 |
} |
|
|
23 |
total <- object@MBclusters |
|
|
24 |
types <- names(object@fdata) |
|
|
25 |
types <- gsub("_[0-9]+", "", types) |
|
|
26 |
coloc <- rainbow(length(unique(types))) |
|
|
27 |
total <- object@MBclusters$pcareduceres |
|
|
28 |
syms <- vector() |
|
|
29 |
plot( |
|
|
30 |
total[, 1], |
|
|
31 |
total[, 2], |
|
|
32 |
xlab = "PC1", |
|
|
33 |
ylab = "PC2", |
|
|
34 |
pch = 20, |
|
|
35 |
cex = 0, |
|
|
36 |
col = "grey", |
|
|
37 |
las = 1 |
|
|
38 |
) |
|
|
39 |
for (i in seq_len(length(unique(types)))) { |
|
|
40 |
f <- types == sort(unique(types))[i] |
|
|
41 |
syms <- append(syms, ((i - 1) %% 25) + 1) |
|
|
42 |
points( |
|
|
43 |
total[f, 1], |
|
|
44 |
total[f, 2], |
|
|
45 |
col = coloc[i], |
|
|
46 |
pch = ((i - 1) %% 25) + 1, |
|
|
47 |
cex = 1 |
|
|
48 |
) |
|
|
49 |
} |
|
|
50 |
legend( |
|
|
51 |
"topright", |
|
|
52 |
legend = sort(unique(types)), |
|
|
53 |
col = coloc, |
|
|
54 |
pch = syms |
|
|
55 |
) |
|
|
56 |
} |
|
|
57 |
) |