Browse code

added corplot manual.

Jaehyun Joo authored on 14/12/2021 05:26:40
Showing 2 changed files

... ...
@@ -1,23 +1,84 @@
1
+##' Correlation plot
2
+##'
3
+##' Visualize correlations between samples or features. All values in a
4
+##' correlation matrix are visualized by rectangles.
5
+##'
6
+##' @param x A matrix or \linkS4class{poplin} object.
7
+##' @param poplin_in Name of a data matrix to retrieve.
8
+##' @param unit A character string specifying whether a correlation matrix is
9
+##'   computed based on samples or features. One of "sample" or "feature".
10
+##' @param use A method for computing correlations in the presence of missing
11
+##'   values. Refer to \code{?cor} for details.
12
+##' @param method A character string specifying which correlation coefficient is
13
+##'   to be computed. Refer to \code{?cor} for details.
14
+##' @param widths Relative widths of heatmap and dendrogram.
15
+##' @param heights Relative heights of heatmap and dendrogram.
16
+##' @param colors A vector of colors for heatmap.
17
+##' @param grid_gap Gap between cells.
18
+##' @param hide_colorbar Logical controlling whether the color bar (legend) is
19
+##'   hidden.
20
+##' @param showticklabels A logical vector of length 2 (x-axis, y-axis). If
21
+##'   \code{FALSE}, the ticks are removed from the side of the plot.
22
+##' @param row_dend_left Logical controlling whether the row dendrogram is
23
+##'   placed on the left on the plot.
24
+##' @param ... Additional arguments passed to [heatmaply::heatmaply].
25
+##' @return \code{gtable} of aligned plots.
26
+##' @name poplin_corplot
27
+NULL
28
+
29
+
1 30
 ##' @export
2 31
 poplin_corplot <- function(x, ...) {
3 32
   UseMethod("poplin_corplot")
4 33
 }
5 34
 
35
+##' @rdname poplin_corplot
6 36
 ##' @export
7 37
 ##' @importFrom heatmaply ggheatmap
8
-poplin_corplot.default <- function(x,
38
+poplin_corplot.default <- function(x, unit = c("sample", "feature"),
9 39
                      use = c("everything", "all.obs", "complete.obs",
10 40
                              "na.or.complete", "pairwise.complete.obs"),
11 41
                      method = c("pearson", "kendall", "spearman"),
12
-                     showticklabels = c(TRUE, TRUE), ...) {
42
+                     widths = NULL, heights = NULL,
43
+                     colors = viridis::viridis(n = 256, alpha = 1,
44
+                                               begin = 0, end = 1,
45
+                                               option = "viridis"),
46
+                     grid_gap = 0, 
47
+                     hide_colorbar = FALSE, showticklabels = c(TRUE, TRUE),
48
+                     row_dend_left = FALSE, ...) {
49
+  unit <- match.arg(unit)
13 50
   use <- match.arg(use)
14 51
   method <- match.arg(method)
52
+  if (unit == "feature") {
53
+    x <- t(x)
54
+  }
15 55
   m <- cor(x, use = use, method = method)
16
-  ggheatmap(m, showticklabels = showticklabels, ...)
56
+  ggheatmap(m, widths = widths, heights = heights,
57
+            grid_gap = grid_gap, colors = colors,
58
+            hide_colorbar = hide_colorbar, showticklabels = showticklabels,
59
+            row_dend_left = row_dend_left, ...)
17 60
 }
18 61
 
62
+
63
+##' @rdname poplin_corplot
19 64
 ##' @export
20
-poplin_corplot.poplin <- function(x, poplin_in , ...) {
65
+poplin_corplot.poplin <- function(x, poplin_in , unit = c("sample", "feature"), 
66
+                                  use = c("everything", "all.obs",
67
+                                          "complete.obs", "na.or.complete",
68
+                                          "pairwise.complete.obs"),
69
+                                  method = c("pearson", "kendall", "spearman"),
70
+                                  widths = NULL, heights = NULL,
71
+                                  colors = viridis::viridis(n = 256, alpha = 1,
72
+                                                            begin = 0, end = 1,
73
+                                                            option = "viridis"),
74
+                                  grid_gap = 0, 
75
+                                  hide_colorbar = FALSE,
76
+                                  showticklabels = c(TRUE, TRUE),
77
+                                  row_dend_left = FALSE, ...) {
21 78
   m <- .verify_and_extract_input(x, poplin_in)
22
-  poplin_corplot.default(m, ...)
79
+  poplin_corplot.default(m, use = use, method = method,
80
+                         widths = widths, heights = heights,
81
+                         colors = colors, hide_colorbar = hide_colorbar,
82
+                         showticklabels = showticklabels,
83
+                         row_dend_left = row_dend_left, ...)
23 84
 }
... ...
@@ -7,17 +7,17 @@
7 7
 ##' @param x A matrix or \linkS4class{poplin} object.
8 8
 ##' @param poplin_in Name of a data matrix to retrieve.
9 9
 ##' @param widths Relative widths of heatmap and dendrogram.
10
-##' @param height Relative height of heatmap and dendrogram.
11
-##' @param grid_gap Gap between cells.
10
+##' @param heights Relative heights of heatmap and dendrogram.
12 11
 ##' @param colors A vector of colors for heatmap.
12
+##' @param grid_gap Gap between cells.
13 13
 ##' @param hide_colorbar Logical controlling whether the color bar (legend) is
14 14
 ##'   hidden.
15 15
 ##' @param showticklabels A logical vector of length 2 (x-axis, y-axis). If
16
-##'   \code{FALSE}, ticks are removed from the side of the plot.
16
+##'   \code{FALSE}, the ticks are removed from the side of the plot.
17 17
 ##' @param row_dend_left Logical controlling whether the row dendrogram is
18 18
 ##'   placed on the left on the plot.
19 19
 ##' @param ... Additional arguments passed to [heatmaply::heatmaply].
20
-##' @return gtable of aligned plot.
20
+##' @return \code{gtable} of aligned plots.
21 21
 ##' @name poplin_naplot
22 22
 NULL
23 23
 
... ...
@@ -30,10 +30,11 @@ poplin_naplot <- function(x, ...) {
30 30
 ##' @export
31 31
 ##' @importFrom heatmaply is.na10 heatmaply
32 32
 poplin_naplot.default <- function(x, widths = NULL, heights = NULL,
33
-                          grid_gap = 1, colors = viridis::viridis(2),
34
-                          hide_colorbar = TRUE, showticklabels = c(TRUE, FALSE),
35
-                          row_dend_left = FALSE, ...) {
36
-  p <- heatmaply(is.na10(x), grid_gap = grid_gap, colors = colors,
33
+                                  colors = viridis::viridis(2), grid_gap = 1, 
34
+                                  hide_colorbar = TRUE,
35
+                                  showticklabels = c(TRUE, FALSE),
36
+                                  row_dend_left = FALSE, ...) {
37
+  p <- heatmaply(is.na10(x), colors = colors, grid_gap = grid_gap,
37 38
                  showticklabels = showticklabels,
38 39
                  row_dend_left = row_dend_left,
39 40
                  return_ppxpy = TRUE, plot_method = "ggplot", ...)
... ...
@@ -48,13 +49,13 @@ poplin_naplot.default <- function(x, widths = NULL, heights = NULL,
48 49
 ##' @rdname poplin_naplot
49 50
 ##' @export
50 51
 poplin_naplot.poplin <- function(x, poplin_in, widths = NULL, heights = NULL,
51
-                                 grid_gap = 1, color = viridis::viridis(2),
52
+                                 color = viridis::viridis(2), grid_gap = 1,
52 53
                                  hide_colorbar = TRUE,
53 54
                                  showticklabels = c(TRUE, FALSE),
54 55
                                  row_dend_left = FALSE, ...) {
55 56
   m <- .verify_and_extract_input(x, poplin_in)
56 57
   poplin_naplot.default(m, widths = widths, heigths = heights,
57
-                        grid_gap = grid_gap, color = color,
58
+                        color = color, grid_gap = grid_gap,
58 59
                         hide_colorbar = hide_colorbar,
59 60
                         showticklabels = showticklabels,
60 61
                         row_dend_left = row_dend_left, ...)