Browse code

Changed dim reduce plotting so that the colnames of the reducedDim object will be displayed on the plot by default. Also added package refs in perplexity functions.

Joshua D. Campbell authored on 15/07/2021 20:24:30
Showing 6 changed files

... ...
@@ -882,7 +882,7 @@ setMethod("plotRPC",
882 882
         diffMeansByK$L <- as.factor(diffMeansByK$L)
883 883
         diffMeansByK$rollmean <- data.table::frollmean(
884 884
             diffMeansByK$meanperpdiffK, n = n, align = "center")
885
-        diffMeansByK <- diffMeansByK[complete.cases(diffMeansByK),]
885
+        diffMeansByK <- diffMeansByK[stats::complete.cases(diffMeansByK),]
886 886
         
887 887
         if (nlevels(dt$L) > 1) {
888 888
             plot <- ggplot2::ggplot(dt[!is.na(perpdiffK), ],
... ...
@@ -939,7 +939,7 @@ setMethod("plotRPC",
939 939
         diffMeansByL$L <- as.factor(diffMeansByL$L)
940 940
         diffMeansByL$rollmean <- data.table::frollmean(
941 941
             diffMeansByL$meanperpdiffL, n = n, align = "center")
942
-        diffMeansByL <- diffMeansByL[complete.cases(diffMeansByL),]
942
+        diffMeansByL <- diffMeansByL[stats::complete.cases(diffMeansByL),]
943 943
         
944 944
         plot <- ggplot2::ggplot(dt[!is.na(perpdiffL), ],
945 945
             ggplot2::aes_string(x = "L", y = "perpdiffL")) +
... ...
@@ -1002,7 +1002,7 @@ setMethod("plotRPC",
1002 1002
         diffMeansByK$K <- as.factor(diffMeansByK$K)
1003 1003
         diffMeansByK$rollmean <- data.table::frollmean(
1004 1004
             diffMeansByK$meanperpdiffK, n = n, align = "center")
1005
-        diffMeansByK <- diffMeansByK[complete.cases(diffMeansByK),]
1005
+        diffMeansByK <- diffMeansByK[stats::complete.cases(diffMeansByK),]
1006 1006
         
1007 1007
         plot <- ggplot2::ggplot(dt[!is.na(perpdiffK), ],
1008 1008
             ggplot2::aes_string(x = "K",
... ...
@@ -1062,7 +1062,7 @@ setMethod("plotRPC",
1062 1062
         diffMeansByL$L <- as.factor(diffMeansByL$L)
1063 1063
         diffMeansByL$rollmean <- data.table::frollmean(
1064 1064
             diffMeansByL$meanperpdiffL, n = n, align = "center")
1065
-        diffMeansByL <- diffMeansByL[complete.cases(diffMeansByL),]
1065
+        diffMeansByL <- diffMeansByL[stats::complete.cases(diffMeansByL),]
1066 1066
         
1067 1067
         plot <- ggplot2::ggplot(dt[!is.na(perpdiffL), ],
1068 1068
             ggplot2::aes_string(x = "L",
... ...
@@ -8,7 +8,7 @@
8 8
 #'  \code{reducedDimNames(x)} if \code{x} is a
9 9
 #'  \linkS4class{SingleCellExperiment} object. Ignored if both \code{dim1} and
10 10
 #'  \code{dim2} are set.
11
-#' @param dim1 Numeric vector. First dimension from data dimension
11
+#' @param dim1 Numeric vector. Second dimension from data dimension
12 12
 #'  reduction output.
13 13
 #' @param dim2 Numeric vector. Second dimension from data dimension
14 14
 #'  reduction output.
... ...
@@ -302,19 +302,23 @@ setMethod("plotDimReduceGrid",
302 302
 #'  with the matrix located in the assay slot under \code{useAssay}. Rows
303 303
 #'  represent features and columns represent cells.
304 304
 #' @param features Character vector. Features in the rownames of counts to plot.
305
+#' @param reducedDimName The name of the dimension reduction slot in
306
+#'  \code{reducedDimNames(x)} if \code{x} is a
307
+#'  \linkS4class{SingleCellExperiment} object. If \code{NULL}, then both
308
+#'  \code{dim1} and \code{dim2} need to be set. Default \code{NULL}.
305 309
 #' @param displayName Character. The column name of
306 310
 #'  \code{rowData(x)} that specifies the display names for
307 311
 #'  the features. Default \code{NULL}, which displays the row names. Only works
308 312
 #'  if \code{x} is a \linkS4class{SingleCellExperiment} object. Overwrites
309 313
 #'  \code{headers}.
310
-#' @param reducedDimName The name of the dimension reduction slot in
311
-#'  \code{reducedDimNames(x)} if \code{x} is a
312
-#'  \linkS4class{SingleCellExperiment} object. If \code{NULL}, then both
313
-#'  \code{dim1} and \code{dim2} need to be set. Default \code{NULL}.
314
-#' @param dim1 Numeric vector. First dimension from data
315
-#'  dimension reduction output to be plotted on the x-axis. Default \code{NULL}.
316
-#' @param dim2 Numeric vector. Second dimension from data dimension
317
-#'  reduction output to be plotted on the y-axis. Default \code{NULL}.
314
+#' @param dim1 Integer or numeric vector. If \code{reducedDimName} is supplied,
315
+#'  then, this will be used as an index to determine which dimension will be
316
+#'  plotted on the x-axis. If \code{reducedDimName} is not supplied, then this
317
+#'  should be a vector which will be plotted on the x-axis. Default \code{1}.
318
+#' @param dim2 Integer or numeric vector. If \code{reducedDimName} is supplied,
319
+#'  then, this will be used as an index to determine which dimension will be
320
+#'  plotted on the y-axis. If \code{reducedDimName} is not supplied, then this
321
+#'  should be a vector which will be plotted on the y-axis. Default \code{2}.
318 322
 #' @param headers Character vector. If \code{NULL}, the corresponding
319 323
 #'  rownames are used as labels. Otherwise, these headers are used to label
320 324
 #'  the features. Only works if \code{displayName} is \code{NULL} and
... ...
@@ -363,8 +367,8 @@ setMethod("plotDimReduceGrid",
363 367
 #' @export
364 368
 setGeneric("plotDimReduceFeature", function(x,
365 369
     features,
366
-    displayName = NULL,
367 370
     reducedDimName = NULL,
371
+    displayName = NULL,    
368 372
     dim1 = NULL,
369 373
     dim2 = NULL,
370 374
     headers = NULL,
... ...
@@ -375,9 +379,9 @@ setGeneric("plotDimReduceFeature", function(x,
375 379
     exactMatch = TRUE,
376 380
     trim = c(-2, 2),
377 381
     limits = c(-2, 2),
378
-    size = 1,
379
-    xlab = "Dimension_1",
380
-    ylab = "Dimension_2",
382
+    size = 0.5,
383
+    xlab = NULL,
384
+    ylab = NULL,
381 385
     colorLow = "blue4",
382 386
     colorMid = "grey90",
383 387
     colorHigh = "firebrick1",
... ...
@@ -402,10 +406,10 @@ setMethod("plotDimReduceFeature",
402 406
     signature(x = "SingleCellExperiment"),
403 407
     function(x,
404 408
         features,
409
+        reducedDimName,
405 410
         displayName = NULL,
406
-        reducedDimName = NULL,
407
-        dim1 = NULL,
408
-        dim2 = NULL,
411
+        dim1 = 1,
412
+        dim2 = 2,
409 413
         headers = NULL,
410 414
         useAssay = "counts",
411 415
         altExpName = "featureSubset",
... ...
@@ -414,9 +418,9 @@ setMethod("plotDimReduceFeature",
414 418
         exactMatch = TRUE,
415 419
         trim = c(-2, 2),
416 420
         limits = c(-2, 2),
417
-        size = 1,
418
-        xlab = "Dimension_1",
419
-        ylab = "Dimension_2",
421
+        size = 0.5,
422
+        xlab = NULL,
423
+        ylab = NULL,
420 424
         colorLow = "blue4",
421 425
         colorMid = "grey90",
422 426
         colorHigh = "firebrick1",
... ...
@@ -426,21 +430,13 @@ setMethod("plotDimReduceFeature",
426 430
 
427 431
         altExp <- SingleCellExperiment::altExp(x, altExpName)
428 432
         counts <- SummarizedExperiment::assay(x, i = useAssay)
429
-
430
-        if (is.null(reducedDimName)) {
431
-          if (is.null(dim1) | is.null(dim2)) {
432
-            stop("If 'reducedDimName' is not supplied, then 'dim1' and 'dim2' ",
433
-                 "must be specified.")
434
-          }
435
-          if (length(dim1) != length(dim2)) {
436
-            stop("'dim1' and 'dim2' must be the same length.")
437
-          }
438
-        } else{
439
-          dims <- SingleCellExperiment::reducedDim(altExp, reducedDimName)
440
-          dim1 <- dims[, 1]
441
-          dim2 <- dims[, 2]
442
-        }
443
-
433
+        reddim <- .processReducedDim(x = altExp,
434
+                                     reducedDimName = reducedDimName,
435
+                                     dim1 = dim1,
436
+                                     dim2 = dim2,
437
+                                     xlab = xlab,
438
+                                     ylab = ylab)
439
+        
444 440
         if (isFALSE(is.null(displayName))) {
445 441
             featuresIx <- retrieveFeatureIndex(features,
446 442
                 x,
... ...
@@ -471,8 +467,8 @@ setMethod("plotDimReduceFeature",
471 467
             }
472 468
         }
473 469
 
474
-        g <- .plotDimReduceFeature(dim1 = dim1,
475
-            dim2 = dim2,
470
+        g <- .plotDimReduceFeature(dim1 = reddim$dim1,
471
+            dim2 = reddim$dim2,
476 472
             counts = counts,
477 473
             features = features,
478 474
             headers = headers,
... ...
@@ -482,8 +478,8 @@ setMethod("plotDimReduceFeature",
482 478
             trim = trim,
483 479
             limits = limits,
484 480
             size = size,
485
-            xlab = xlab,
486
-            ylab = ylab,
481
+            xlab = reddim$xlab,
482
+            ylab = reddim$ylab,
487 483
             colorLow = colorLow,
488 484
             colorMid = colorMid,
489 485
             colorHigh = colorHigh,
... ...
@@ -519,7 +515,7 @@ setMethod("plotDimReduceFeature",
519 515
         exactMatch = TRUE,
520 516
         trim = c(-2, 2),
521 517
         limits = c(-2, 2),
522
-        size = 1,
518
+        size = 0.5,
523 519
         xlab = "Dimension_1",
524 520
         ylab = "Dimension_2",
525 521
         colorLow = "blue4",
... ...
@@ -660,10 +656,14 @@ setMethod("plotDimReduceFeature",
660 656
 #'  \code{reducedDimNames(x)} if \code{x} is a
661 657
 #'  \linkS4class{SingleCellExperiment} object. Ignored if both \code{dim1} and
662 658
 #'  \code{dim2} are set.
663
-#' @param dim1 Numeric vector.
664
-#'  First dimension from data dimension reduction output.
665
-#' @param dim2 Numeric vector.
666
-#'  Second dimension from data dimension reduction output.
659
+#' @param dim1 Integer or numeric vector. If \code{reducedDimName} is supplied,
660
+#'  then, this will be used as an index to determine which dimension will be
661
+#'  plotted on the x-axis. If \code{reducedDimName} is not supplied, then this
662
+#'  should be a vector which will be plotted on the x-axis. Default \code{1}.
663
+#' @param dim2 Integer or numeric vector. If \code{reducedDimName} is supplied,
664
+#'  then, this will be used as an index to determine which dimension will be
665
+#'  plotted on the y-axis. If \code{reducedDimName} is not supplied, then this
666
+#'  should be a vector which will be plotted on the y-axis. Default \code{2}.
667 667
 #' @param useAssay A string specifying which \link{assay}
668 668
 #'  slot to use if \code{x} is a
669 669
 #'  \linkS4class{SingleCellExperiment} object. Default "counts".
... ...
@@ -673,15 +673,15 @@ setMethod("plotDimReduceFeature",
673 673
 #'  \code{x} is a matrix object.
674 674
 #' @param modules Character vector. Module(s) from celda model to be plotted.
675 675
 #'  e.g. c("1", "2").
676
-#' @param rescale Logical.
677
-#'  Whether rows of the matrix should be rescaled to [0, 1]. Default TRUE.
678
-#' @param limits Passed to \link{scale_colour_gradient}. The range
679
-#'  of color scale.
680
-#' @param size Numeric. Sets size of point on plot. Default 1.
676
+#' @param size Numeric. Sets size of point on plot. Default 0.5.
681 677
 #' @param xlab Character vector. Label for the x-axis. Default "Dimension_1".
682 678
 #' @param ylab Character vector. Label for the y-axis. Default "Dimension_2".
683 679
 #' @param colorLow Character. A color available from `colors()`.
684 680
 #'  The color will be used to signify the lowest values on the scale.
681
+#' @param rescale Logical.
682
+#'  Whether rows of the matrix should be rescaled to [0, 1]. Default TRUE.
683
+#' @param limits Passed to \link{scale_colour_gradient}. The range
684
+#'  of color scale.
685 685
 #' @param colorHigh Character. A color available from `colors()`.
686 686
 #'  The color will be used to signify the highest values on the scale.
687 687
 #' @param ncol Integer. Passed to \link[ggplot2]{facet_wrap}. Specify the
... ...
@@ -696,17 +696,17 @@ setMethod("plotDimReduceFeature",
696 696
 setGeneric("plotDimReduceModule",
697 697
     function(x,
698 698
         reducedDimName,
699
-        dim1 = NULL,
700
-        dim2 = NULL,
701 699
         useAssay = "counts",
702 700
         altExpName = "featureSubset",
703 701
         celdaMod,
704 702
         modules = NULL,
703
+        dim1 = NULL,
704
+        dim2 = NULL,
705
+        size = 0.5,
706
+        xlab = NULL,
707
+        ylab = NULL,
705 708
         rescale = TRUE,
706 709
         limits = c(0, 1),
707
-        size = 1,
708
-        xlab = "Dimension_1",
709
-        ylab = "Dimension_2",
710 710
         colorLow = "grey90",
711 711
         colorHigh = "firebrick1",
712 712
         ncol = NULL,
... ...
@@ -726,49 +726,44 @@ setMethod("plotDimReduceModule",
726 726
     signature(x = "SingleCellExperiment"),
727 727
     function(x,
728 728
         reducedDimName,
729
-        dim1 = NULL,
730
-        dim2 = NULL,
731 729
         useAssay = "counts",
732 730
         altExpName = "featureSubset",
733 731
         modules = NULL,
732
+        dim1 = 1,
733
+        dim2 = 2,
734
+        size = 0.5,
735
+        xlab = NULL,
736
+        ylab = NULL,
734 737
         rescale = TRUE,
735 738
         limits = c(0, 1),
736
-        size = 1,
737
-        xlab = "Dimension_1",
738
-        ylab = "Dimension_2",
739 739
         colorLow = "grey90",
740 740
         colorHigh = "firebrick1",
741 741
         ncol = NULL,
742 742
         decreasing = FALSE) {
743 743
 
744
+        # Get reduced dim object
744 745
         altExp <- SingleCellExperiment::altExp(x, altExpName)
746
+        reddim <- .processReducedDim(x = altExp,
747
+                                     reducedDimName = reducedDimName,
748
+                                     dim1 = dim1,
749
+                                     dim2 = dim2,
750
+                                     xlab = xlab,
751
+                                     ylab = ylab)
745 752
 
746
-        if (is.null(dim1)) {
747
-            dim1 <- SingleCellExperiment::reducedDim(altExp,
748
-                reducedDimName)[, 1]
749
-        }
750
-
751
-        if (is.null(dim2)) {
752
-            dim2 <- SingleCellExperiment::reducedDim(altExp,
753
-                reducedDimName)[, 2]
754
-        }
755
-
756
-        counts <- SummarizedExperiment::assay(x, i = useAssay)
757 753
         factorized <- factorizeMatrix(x,
758 754
             useAssay = useAssay,
759 755
             altExpName = altExpName,
760 756
             type = "proportion")
761 757
 
762
-        g <- .plotDimReduceModule(dim1 = dim1,
763
-            dim2 = dim2,
764
-            counts = counts,
758
+        g <- .plotDimReduceModule(dim1 = reddim$dim1,
759
+            dim2 = reddim$dim2,
765 760
             factorized = factorized,
766 761
             modules = modules,
767 762
             rescale = rescale,
768 763
             limits = limits,
769 764
             size = size,
770
-            xlab = xlab,
771
-            ylab = ylab,
765
+            xlab = reddim$xlab,
766
+            ylab = reddim$ylab,
772 767
             colorLow = colorLow,
773 768
             colorHigh = colorHigh,
774 769
             ncol = ncol,
... ...
@@ -792,32 +787,36 @@ setMethod("plotDimReduceModule",
792 787
 setMethod("plotDimReduceModule",
793 788
     signature(x = "ANY"),
794 789
     function(x,
795
-        dim1,
796
-        dim2,
797 790
         celdaMod,
798 791
         modules = NULL,
799
-        rescale = TRUE,
800
-        limits = c(0, 1),
801
-        size = 1,
792
+        dim1,
793
+        dim2,
794
+        size = 0.5,
802 795
         xlab = "Dimension_1",
803 796
         ylab = "Dimension_2",
797
+        rescale = TRUE,
798
+        limits = c(0, 1),
804 799
         colorLow = "grey90",
805 800
         colorHigh = "firebrick1",
806 801
         ncol = NULL,
807 802
         decreasing = FALSE) {
808 803
 
809
-        x <- as.matrix(x)
810 804
         factorized <- factorizeMatrix(x = x, celdaMod = celdaMod)
811
-        g <- .plotDimReduceModule(dim1 = dim1,
812
-            dim2 = dim2,
813
-            counts = x,
805
+        reddim <- .processReducedDim(x = x,
806
+                                     dim1 = dim1,
807
+                                     dim2 = dim2,
808
+                                     xlab = xlab,
809
+                                     ylab = ylab)
810
+        
811
+        g <- .plotDimReduceModule(dim1 = reddim$dim1,
812
+            dim2 = reddim$dim2,
814 813
             factorized = factorized,
815 814
             modules = modules,
816 815
             rescale = rescale,
817 816
             limits = limits,
818 817
             size = size,
819
-            xlab = xlab,
820
-            ylab = ylab,
818
+            xlab = reddim$xlab,
819
+            ylab = reddim$ylab,
821 820
             colorLow = colorLow,
822 821
             colorHigh = colorHigh,
823 822
             ncol = ncol,
... ...
@@ -829,7 +828,6 @@ setMethod("plotDimReduceModule",
829 828
 
830 829
 .plotDimReduceModule <- function(dim1,
831 830
     dim2,
832
-    counts,
833 831
     factorized,
834 832
     modules,
835 833
     rescale,
... ...
@@ -921,13 +919,17 @@ setMethod("plotDimReduceModule",
921 919
 #'  \code{dim2} are set.
922 920
 #' @param altExpName The name for the \link{altExp} slot
923 921
 #'  to use. Default "featureSubset".
924
-#' @param dim1 Numeric vector. First dimension from data
925
-#'  dimension reduction output.
926
-#' @param dim2 Numeric vector. Second dimension from data
927
-#'  dimension reduction output.
928
-#' @param size Numeric. Sets size of point on plot. Default 1.
929
-#' @param xlab Character vector. Label for the x-axis. Default "Dimension_1".
930
-#' @param ylab Character vector. Label for the y-axis. Default "Dimension_2".
922
+#' @param dim1 Integer or numeric vector. If \code{reducedDimName} is supplied,
923
+#'  then, this will be used as an index to determine which dimension will be
924
+#'  plotted on the x-axis. If \code{reducedDimName} is not supplied, then this
925
+#'  should be a vector which will be plotted on the x-axis. Default \code{1}.
926
+#' @param dim2 Integer or numeric vector. If \code{reducedDimName} is supplied,
927
+#'  then, this will be used as an index to determine which dimension will be
928
+#'  plotted on the y-axis. If \code{reducedDimName} is not supplied, then this
929
+#'  should be a vector which will be plotted on the y-axis. Default \code{2}.
930
+#' @param size Numeric. Sets size of point on plot. Default \code{0.5}.
931
+#' @param xlab Character vector. Label for the x-axis. Default \code{NULL}.
932
+#' @param ylab Character vector. Label for the y-axis. Default \code{NULL}.
931 933
 #' @param specificClusters Numeric vector.
932 934
 #'  Only color cells in the specified clusters.
933 935
 #'  All other cells will be grey.
... ...
@@ -947,9 +949,9 @@ setGeneric("plotDimReduceCluster",
947 949
         altExpName = "featureSubset",
948 950
         dim1 = NULL,
949 951
         dim2 = NULL,
950
-        size = 1,
951
-        xlab = "Dimension_1",
952
-        ylab = "Dimension_2",
952
+        size = 0.5,
953
+        xlab = NULL,
954
+        ylab = NULL,
953 955
         specificClusters = NULL,
954 956
         labelClusters = FALSE,
955 957
         groupBy = NULL,
... ...
@@ -970,11 +972,11 @@ setMethod("plotDimReduceCluster",
970 972
     function(x,
971 973
         reducedDimName,
972 974
         altExpName = "featureSubset",
973
-        dim1 = NULL,
974
-        dim2 = NULL,
975
-        size = 1,
976
-        xlab = "Dimension_1",
977
-        ylab = "Dimension_2",
975
+        dim1 = 1,
976
+        dim2 = 2,
977
+        size = 0.5,
978
+        xlab = NULL,
979
+        ylab = NULL,
978 980
         specificClusters = NULL,
979 981
         labelClusters = FALSE,
980 982
         groupBy = NULL,
... ...
@@ -989,22 +991,19 @@ setMethod("plotDimReduceCluster",
989 991
         }
990 992
         cluster <- SummarizedExperiment::colData(altExp)[["celda_cell_cluster"]]
991 993
 
992
-        if (is.null(dim1)) {
993
-            dim1 <- SingleCellExperiment::reducedDim(altExp,
994
-                reducedDimName)[, 1]
995
-        }
996
-
997
-        if (is.null(dim2)) {
998
-            dim2 <- SingleCellExperiment::reducedDim(altExp,
999
-                reducedDimName)[, 2]
1000
-        }
994
+        reddim <- .processReducedDim(x = altExp,
995
+                                     reducedDimName = reducedDimName,
996
+                                     dim1 = dim1,
997
+                                     dim2 = dim2,
998
+                                     xlab = xlab,
999
+                                     ylab = ylab)
1001 1000
 
1002
-        g <- .plotDimReduceCluster(dim1 = dim1,
1003
-            dim2 = dim2,
1001
+        g <- .plotDimReduceCluster(dim1 = reddim$dim1,
1002
+            dim2 = reddim$dim2,
1004 1003
             cluster = cluster,
1005 1004
             size = size,
1006
-            xlab = xlab,
1007
-            ylab = ylab,
1005
+            xlab = reddim$xlab,
1006
+            ylab = reddim$ylab,
1008 1007
             specificClusters = specificClusters,
1009 1008
             labelClusters = labelClusters,
1010 1009
             groupBy = groupBy,
... ...
@@ -1029,7 +1028,7 @@ setMethod("plotDimReduceCluster",
1029 1028
     function(x,
1030 1029
         dim1,
1031 1030
         dim2,
1032
-        size = 1,
1031
+        size = 0.5,
1033 1032
         xlab = "Dimension_1",
1034 1033
         ylab = "Dimension_2",
1035 1034
         specificClusters = NULL,
... ...
@@ -1037,12 +1036,17 @@ setMethod("plotDimReduceCluster",
1037 1036
         groupBy = NULL,
1038 1037
         labelSize = 3.5) {
1039 1038
 
1040
-        g <- .plotDimReduceCluster(dim1 = dim1,
1041
-            dim2 = dim2,
1039
+      reddim <- .processReducedDim(x = x,
1040
+                                   dim1 = dim1,
1041
+                                   dim2 = dim2,
1042
+                                   xlab = xlab,
1043
+                                   ylab = ylab)
1044
+      g <- .plotDimReduceCluster(dim1 = reddim$dim1,
1045
+            dim2 = reddim$dim2,
1042 1046
             cluster = x,
1043 1047
             size = size,
1044
-            xlab = xlab,
1045
-            ylab = ylab,
1048
+            xlab = reddim$xlab,
1049
+            ylab = reddim$ylab,
1046 1050
             specificClusters = specificClusters,
1047 1051
             labelClusters = labelClusters,
1048 1052
             groupBy = groupBy,
... ...
@@ -1305,3 +1309,59 @@ setMethod("plotCeldaViolin",
1305 1309
 
1306 1310
     return(p)
1307 1311
 }
1312
+
1313
+
1314
+
1315
+
1316
+.processReducedDim <- function(x,
1317
+                           reducedDimName = NULL,
1318
+                           dim1 = NULL,
1319
+                           dim2 = NULL,
1320
+                           xlab = NULL,
1321
+                           ylab = NULL) {
1322
+  if(inherits(x, "SingleCellExperiment") & !is.null(reducedDimName)) {
1323
+    reddim <- SingleCellExperiment::reducedDim(x, reducedDimName)
1324
+    
1325
+    # Get dims to retrieve from redDim object
1326
+    if(is.null(dim1)) dim1 <- 1
1327
+    if(is.null(dim2)) dim2 <- 2
1328
+    
1329
+    # Get labels
1330
+    xlab <- colnames(reddim)[dim1]
1331
+    ylab <- colnames(reddim)[dim2]
1332
+    
1333
+    # Set up return object
1334
+    res <- list(dim1 = reddim[,dim1], dim2 = reddim[,dim2], xlab = xlab, ylab = ylab)
1335
+    
1336
+  } else if (!is.null(dim1) & !is.null(dim2)) {
1337
+    if(inherits(x, c("matrix", "Matrix"))) {
1338
+      if(length(dim1) != ncol(x)) {
1339
+        stop("'dim1' needs to be the same length as 'x'.")
1340
+      }
1341
+      if(length(dim2) != ncol(x)) {
1342
+        stop("'dim2' needs to be the same length as 'x'.")
1343
+      }
1344
+    } else {
1345
+      if(length(dim1) != length(x)) {
1346
+        stop("'dim1' needs to be the same length as 'x'.")
1347
+      }
1348
+      if(length(dim2) != length(x)) {
1349
+        stop("'dim2' needs to be the same length as 'x'.")
1350
+      }
1351
+    }
1352
+    if(is.null(xlab)) xlab <- "Dimension 1"
1353
+    if(is.null(ylab)) ylab <- "Dimension 2"
1354
+    
1355
+    res <- list(dim1 = dim1, dim2 = dim2, xlab = xlab, ylab = ylab)
1356
+    
1357
+  } else {
1358
+    stop("'x' can be supplied as a SingleCelExperiment along with ",
1359
+    "'reducedDimName' and 'dim1' and 'dim2' can be used to specify which ",
1360
+    "dimensions to plot on the x- and y-axis, respectively. Alternatively, ",
1361
+    "'x', 'dim1' and 'dim2' can be supplied as vectors of the same length ",
1362
+    "where 'dim1' is the x-axis, 'dim2', is the y-axis, and 'x' will be used ",
1363
+    "to color the points.")
1364
+  }
1365
+  
1366
+  return(res)
1367
+} 
... ...
@@ -12,9 +12,9 @@ plotDimReduceCluster(
12 12
   altExpName = "featureSubset",
13 13
   dim1 = NULL,
14 14
   dim2 = NULL,
15
-  size = 1,
16
-  xlab = "Dimension_1",
17
-  ylab = "Dimension_2",
15
+  size = 0.5,
16
+  xlab = NULL,
17
+  ylab = NULL,
18 18
   specificClusters = NULL,
19 19
   labelClusters = FALSE,
20 20
   groupBy = NULL,
... ...
@@ -25,11 +25,11 @@ plotDimReduceCluster(
25 25
   x,
26 26
   reducedDimName,
27 27
   altExpName = "featureSubset",
28
-  dim1 = NULL,
29
-  dim2 = NULL,
30
-  size = 1,
31
-  xlab = "Dimension_1",
32
-  ylab = "Dimension_2",
28
+  dim1 = 1,
29
+  dim2 = 2,
30
+  size = 0.5,
31
+  xlab = NULL,
32
+  ylab = NULL,
33 33
   specificClusters = NULL,
34 34
   labelClusters = FALSE,
35 35
   groupBy = NULL,
... ...
@@ -40,7 +40,7 @@ plotDimReduceCluster(
40 40
   x,
41 41
   dim1,
42 42
   dim2,
43
-  size = 1,
43
+  size = 0.5,
44 44
   xlab = "Dimension_1",
45 45
   ylab = "Dimension_2",
46 46
   specificClusters = NULL,
... ...
@@ -63,17 +63,21 @@ column in \code{colData(x)}.}
63 63
 \item{altExpName}{The name for the \link{altExp} slot
64 64
 to use. Default "featureSubset".}
65 65
 
66
-\item{dim1}{Numeric vector. First dimension from data
67
-dimension reduction output.}
66
+\item{dim1}{Integer or numeric vector. If \code{reducedDimName} is supplied,
67
+then, this will be used as an index to determine which dimension will be
68
+plotted on the x-axis. If \code{reducedDimName} is not supplied, then this
69
+should be a vector which will be plotted on the x-axis. Default \code{1}.}
68 70
 
69
-\item{dim2}{Numeric vector. Second dimension from data
70
-dimension reduction output.}
71
+\item{dim2}{Integer or numeric vector. If \code{reducedDimName} is supplied,
72
+then, this will be used as an index to determine which dimension will be
73
+plotted on the y-axis. If \code{reducedDimName} is not supplied, then this
74
+should be a vector which will be plotted on the y-axis. Default \code{2}.}
71 75
 
72
-\item{size}{Numeric. Sets size of point on plot. Default 1.}
76
+\item{size}{Numeric. Sets size of point on plot. Default \code{0.5}.}
73 77
 
74
-\item{xlab}{Character vector. Label for the x-axis. Default "Dimension_1".}
78
+\item{xlab}{Character vector. Label for the x-axis. Default \code{NULL}.}
75 79
 
76
-\item{ylab}{Character vector. Label for the y-axis. Default "Dimension_2".}
80
+\item{ylab}{Character vector. Label for the y-axis. Default \code{NULL}.}
77 81
 
78 82
 \item{specificClusters}{Numeric vector.
79 83
 Only color cells in the specified clusters.
... ...
@@ -9,8 +9,8 @@
9 9
 plotDimReduceFeature(
10 10
   x,
11 11
   features,
12
-  displayName = NULL,
13 12
   reducedDimName = NULL,
13
+  displayName = NULL,
14 14
   dim1 = NULL,
15 15
   dim2 = NULL,
16 16
   headers = NULL,
... ...
@@ -21,9 +21,9 @@ plotDimReduceFeature(
21 21
   exactMatch = TRUE,
22 22
   trim = c(-2, 2),
23 23
   limits = c(-2, 2),
24
-  size = 1,
25
-  xlab = "Dimension_1",
26
-  ylab = "Dimension_2",
24
+  size = 0.5,
25
+  xlab = NULL,
26
+  ylab = NULL,
27 27
   colorLow = "blue4",
28 28
   colorMid = "grey90",
29 29
   colorHigh = "firebrick1",
... ...
@@ -35,10 +35,10 @@ plotDimReduceFeature(
35 35
 \S4method{plotDimReduceFeature}{SingleCellExperiment}(
36 36
   x,
37 37
   features,
38
-  displayName = NULL,
39 38
   reducedDimName = NULL,
40
-  dim1 = NULL,
41
-  dim2 = NULL,
39
+  displayName = NULL,
40
+  dim1 = 1,
41
+  dim2 = 2,
42 42
   headers = NULL,
43 43
   useAssay = "counts",
44 44
   altExpName = "featureSubset",
... ...
@@ -47,9 +47,9 @@ plotDimReduceFeature(
47 47
   exactMatch = TRUE,
48 48
   trim = c(-2, 2),
49 49
   limits = c(-2, 2),
50
-  size = 1,
51
-  xlab = "Dimension_1",
52
-  ylab = "Dimension_2",
50
+  size = 0.5,
51
+  xlab = NULL,
52
+  ylab = NULL,
53 53
   colorLow = "blue4",
54 54
   colorMid = "grey90",
55 55
   colorHigh = "firebrick1",
... ...
@@ -69,7 +69,7 @@ plotDimReduceFeature(
69 69
   exactMatch = TRUE,
70 70
   trim = c(-2, 2),
71 71
   limits = c(-2, 2),
72
-  size = 1,
72
+  size = 0.5,
73 73
   xlab = "Dimension_1",
74 74
   ylab = "Dimension_2",
75 75
   colorLow = "blue4",
... ...
@@ -87,22 +87,26 @@ represent features and columns represent cells.}
87 87
 
88 88
 \item{features}{Character vector. Features in the rownames of counts to plot.}
89 89
 
90
+\item{reducedDimName}{The name of the dimension reduction slot in
91
+\code{reducedDimNames(x)} if \code{x} is a
92
+\linkS4class{SingleCellExperiment} object. If \code{NULL}, then both
93
+\code{dim1} and \code{dim2} need to be set. Default \code{NULL}.}
94
+
90 95
 \item{displayName}{Character. The column name of
91 96
 \code{rowData(x)} that specifies the display names for
92 97
 the features. Default \code{NULL}, which displays the row names. Only works
93 98
 if \code{x} is a \linkS4class{SingleCellExperiment} object. Overwrites
94 99
 \code{headers}.}
95 100
 
96
-\item{reducedDimName}{The name of the dimension reduction slot in
97
-\code{reducedDimNames(x)} if \code{x} is a
98
-\linkS4class{SingleCellExperiment} object. If \code{NULL}, then both
99
-\code{dim1} and \code{dim2} need to be set. Default \code{NULL}.}
100
-
101
-\item{dim1}{Numeric vector. First dimension from data
102
-dimension reduction output to be plotted on the x-axis. Default \code{NULL}.}
101
+\item{dim1}{Integer or numeric vector. If \code{reducedDimName} is supplied,
102
+then, this will be used as an index to determine which dimension will be
103
+plotted on the x-axis. If \code{reducedDimName} is not supplied, then this
104
+should be a vector which will be plotted on the x-axis. Default \code{1}.}
103 105
 
104
-\item{dim2}{Numeric vector. Second dimension from data dimension
105
-reduction output to be plotted on the y-axis. Default \code{NULL}.}
106
+\item{dim2}{Integer or numeric vector. If \code{reducedDimName} is supplied,
107
+then, this will be used as an index to determine which dimension will be
108
+plotted on the y-axis. If \code{reducedDimName} is not supplied, then this
109
+should be a vector which will be plotted on the y-axis. Default \code{2}.}
106 110
 
107 111
 \item{headers}{Character vector. If \code{NULL}, the corresponding
108 112
 rownames are used as labels. Otherwise, these headers are used to label
... ...
@@ -76,7 +76,7 @@ row of the matrix will be plotted as a separate facet.}
76 76
 \linkS4class{SingleCellExperiment} object. Ignored if both \code{dim1} and
77 77
 \code{dim2} are set.}
78 78
 
79
-\item{dim1}{Numeric vector. First dimension from data dimension
79
+\item{dim1}{Numeric vector. Second dimension from data dimension
80 80
 reduction output.}
81 81
 
82 82
 \item{dim2}{Numeric vector. Second dimension from data dimension
... ...
@@ -10,17 +10,17 @@
10 10
 plotDimReduceModule(
11 11
   x,
12 12
   reducedDimName,
13
-  dim1 = NULL,
14
-  dim2 = NULL,
15 13
   useAssay = "counts",
16 14
   altExpName = "featureSubset",
17 15
   celdaMod,
18 16
   modules = NULL,
17
+  dim1 = NULL,
18
+  dim2 = NULL,
19
+  size = 0.5,
20
+  xlab = NULL,
21
+  ylab = NULL,
19 22
   rescale = TRUE,
20 23
   limits = c(0, 1),
21
-  size = 1,
22
-  xlab = "Dimension_1",
23
-  ylab = "Dimension_2",
24 24
   colorLow = "grey90",
25 25
   colorHigh = "firebrick1",
26 26
   ncol = NULL,
... ...
@@ -30,16 +30,16 @@ plotDimReduceModule(
30 30
 \S4method{plotDimReduceModule}{SingleCellExperiment}(
31 31
   x,
32 32
   reducedDimName,
33
-  dim1 = NULL,
34
-  dim2 = NULL,
35 33
   useAssay = "counts",
36 34
   altExpName = "featureSubset",
37 35
   modules = NULL,
36
+  dim1 = 1,
37
+  dim2 = 2,
38
+  size = 0.5,
39
+  xlab = NULL,
40
+  ylab = NULL,
38 41
   rescale = TRUE,
39 42
   limits = c(0, 1),
40
-  size = 1,
41
-  xlab = "Dimension_1",
42
-  ylab = "Dimension_2",
43 43
   colorLow = "grey90",
44 44
   colorHigh = "firebrick1",
45 45
   ncol = NULL,
... ...
@@ -48,15 +48,15 @@ plotDimReduceModule(
48 48
 
49 49
 \S4method{plotDimReduceModule}{ANY}(
50 50
   x,
51
-  dim1,
52
-  dim2,
53 51
   celdaMod,
54 52
   modules = NULL,
55
-  rescale = TRUE,
56
-  limits = c(0, 1),
57
-  size = 1,
53
+  dim1,
54
+  dim2,
55
+  size = 0.5,
58 56
   xlab = "Dimension_1",
59 57
   ylab = "Dimension_2",
58
+  rescale = TRUE,
59
+  limits = c(0, 1),
60 60
   colorLow = "grey90",
61 61
   colorHigh = "firebrick1",
62 62
   ncol = NULL,
... ...
@@ -73,12 +73,6 @@ represent features and columns represent cells.}
73 73
 \linkS4class{SingleCellExperiment} object. Ignored if both \code{dim1} and
74 74
 \code{dim2} are set.}
75 75
 
76
-\item{dim1}{Numeric vector.
77
-First dimension from data dimension reduction output.}
78
-
79
-\item{dim2}{Numeric vector.
80
-Second dimension from data dimension reduction output.}
81
-
82 76
 \item{useAssay}{A string specifying which \link{assay}
83 77
 slot to use if \code{x} is a
84 78
 \linkS4class{SingleCellExperiment} object. Default "counts".}
... ...
@@ -92,18 +86,28 @@ to use. Default "featureSubset".}
92 86
 \item{modules}{Character vector. Module(s) from celda model to be plotted.
93 87
 e.g. c("1", "2").}
94 88
 
95
-\item{rescale}{Logical.
96
-Whether rows of the matrix should be rescaled to [0, 1]. Default TRUE.}
89
+\item{dim1}{Integer or numeric vector. If \code{reducedDimName} is supplied,
90
+then, this will be used as an index to determine which dimension will be
91
+plotted on the x-axis. If \code{reducedDimName} is not supplied, then this
92
+should be a vector which will be plotted on the x-axis. Default \code{1}.}
97 93
 
98
-\item{limits}{Passed to \link{scale_colour_gradient}. The range
99
-of color scale.}
94
+\item{dim2}{Integer or numeric vector. If \code{reducedDimName} is supplied,
95
+then, this will be used as an index to determine which dimension will be
96
+plotted on the y-axis. If \code{reducedDimName} is not supplied, then this
97
+should be a vector which will be plotted on the y-axis. Default \code{2}.}
100 98
 
101
-\item{size}{Numeric. Sets size of point on plot. Default 1.}
99
+\item{size}{Numeric. Sets size of point on plot. Default 0.5.}
102 100
 
103 101
 \item{xlab}{Character vector. Label for the x-axis. Default "Dimension_1".}
104 102
 
105 103
 \item{ylab}{Character vector. Label for the y-axis. Default "Dimension_2".}
106 104
 
105
+\item{rescale}{Logical.
106
+Whether rows of the matrix should be rescaled to [0, 1]. Default TRUE.}
107
+
108
+\item{limits}{Passed to \link{scale_colour_gradient}. The range
109
+of color scale.}
110
+
107 111
 \item{colorLow}{Character. A color available from `colors()`.
108 112
 The color will be used to signify the lowest values on the scale.}
109 113