diff --git a/DESCRIPTION b/DESCRIPTION index e4ed84ef585cb45400a7f4a6d4ccf7c964637570..c314d23b00e6b89a59b35115977100a678ecbe97 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: splatter Type: Package Title: Simple Simulation of Single-cell RNA Sequencing Data -Version: 0.99.13 -Date: 2017-03-25 +Version: 0.99.14 +Date: 2017-03-28 Author: Luke Zappia Authors@R: c(person("Luke", "Zappia", role = c("aut", "cre"), @@ -46,7 +46,8 @@ Suggests: BiocStyle, covr, S4Vectors, - SummarizedExperiment + SummarizedExperiment, + cowplot biocViews: SingleCell, RNASeq, Transcriptomics, GeneExpression, Sequencing, Software URL: https://github.com/Oshlack/splatter diff --git a/NAMESPACE b/NAMESPACE index 2fac85b2ceab64fb95336e95c5c64a2a2688a917..e56ae21db7a3edff1c5cfb54b66055001bf93d77 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,6 +20,9 @@ export(lun2Estimate) export(lun2Simulate) export(lunEstimate) export(lunSimulate) +export(makeCompPanel) +export(makeDiffPanel) +export(makeOverallPanel) export(newLun2Params) export(newLunParams) export(newSCDDParams) @@ -58,17 +61,20 @@ importFrom(checkmate,checkIntegerish) importFrom(checkmate,checkNumber) importFrom(checkmate,checkNumeric) importFrom(ggplot2,aes_string) +importFrom(ggplot2,element_blank) importFrom(ggplot2,geom_abline) importFrom(ggplot2,geom_boxplot) importFrom(ggplot2,geom_hline) importFrom(ggplot2,geom_point) importFrom(ggplot2,geom_smooth) -importFrom(ggplot2,geom_violin) importFrom(ggplot2,ggplot) importFrom(ggplot2,ggtitle) +importFrom(ggplot2,scale_colour_manual) +importFrom(ggplot2,scale_fill_manual) importFrom(ggplot2,scale_x_log10) importFrom(ggplot2,scale_y_continuous) importFrom(ggplot2,scale_y_log10) +importFrom(ggplot2,theme) importFrom(ggplot2,theme_minimal) importFrom(ggplot2,xlab) importFrom(ggplot2,ylab) diff --git a/NEWS.md b/NEWS.md index 124ce57ccd9cde8fe998b4341fb1d2feeb1fca9d..3936f24c405be1e5c880b3ce466d6f684cac493b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# 0.99.14 + +* Add functions for making comparison panels +* Add panel section to vignette +* Change variance plot scale (for consistency) + # 0.99.13 * Modify how Lun2Params stores gene paramters to use data.frame diff --git a/R/compare.R b/R/compare.R index 23aa2710ccaf96391156870e6d71c745eb749580..4e0feb06054e2b8108172f6e47df11d2d872a3a4 100644 --- a/R/compare.R +++ b/R/compare.R @@ -4,6 +4,10 @@ #' comparing them. #' #' @param sces named list of SCESet objects to combine and compare. +#' @param point.size size of points in scatter plots. +#' @param point.alpha opacity of points in scatter plots. +#' @param fits whether to include fits in scatter plots. +#' @param colours vector of colours to use for each dataset. #' #' @details #' The returned list has three items: @@ -44,14 +48,25 @@ #' names(comparison) #' names(comparison$Plots) #' @importFrom ggplot2 ggplot aes_string geom_point geom_smooth geom_boxplot -#' geom_violin scale_y_continuous scale_y_log10 scale_x_log10 xlab ylab ggtitle -#' theme_minimal +#' scale_y_continuous scale_y_log10 scale_x_log10 xlab ylab ggtitle +#' theme_minimal scale_colour_manual scale_fill_manual #' @importFrom scater cpm<- #' @export -compareSCESets <- function(sces) { +compareSCESets <- function(sces, point.size = 0.1, point.alpha = 0.1, + fits = TRUE, colours = NULL) { checkmate::assertList(sces, types = "SCESet", any.missing = FALSE, min.len = 1, names = "unique") + checkmate::assertNumber(point.size, finite = TRUE) + checkmate::assertNumber(point.alpha, lower = 0, upper = 1) + checkmate::assertLogical(fits, any.missing = FALSE, len = 1) + + if (!is.null(colours)) { + checkmate::assertCharacter(colours, any.missing = FALSE, + len = length(sces)) + } else { + colours <- scales::hue_pal()(length(sces)) + } for (name in names(sces)) { sce <- sces[[name]] @@ -84,25 +99,27 @@ compareSCESets <- function(sces) { colour = "Dataset")) + #geom_violin(draw_quantiles = c(0.25, 0.5, 0.75)) + geom_boxplot() + + scale_colour_manual(values = colours) + ylab(expression(paste("Mean ", log[2], "(CPM + 1)"))) + ggtitle("Distribution of mean expression") + theme_minimal() vars <- ggplot(fData.all, - aes_string(x = "Dataset", y = "VarCPM", + aes_string(x = "Dataset", y = "VarLogCPM", colour = "Dataset")) + #geom_violin(draw_quantiles = c(0.25, 0.5, 0.75)) + geom_boxplot() + - scale_y_log10(labels = scales::comma) + - ylab("CPM Variance") + + scale_colour_manual(values = colours) + + ylab(expression(paste("Variance ", log[2], "(CPM + 1)"))) + ggtitle("Distribution of variance") + theme_minimal() mean.var <- ggplot(fData.all, aes_string(x = "MeanLogCPM", y = "VarLogCPM", colour = "Dataset", fill = "Dataset")) + - geom_point(size = 0.1, alpha = 0.1) + - geom_smooth() + + geom_point(size = point.size, alpha = point.alpha) + + scale_colour_manual(values = colours) + + scale_fill_manual(values = colours) + xlab(expression(paste("Mean ", log[2], "(CPM + 1)"))) + ylab(expression(paste("Variance ", log[2], "(CPM + 1)"))) + ggtitle("Mean-variance relationship") + @@ -113,6 +130,7 @@ compareSCESets <- function(sces) { colour = "Dataset")) + geom_boxplot() + scale_y_continuous(labels = scales::comma) + + scale_colour_manual(values = colours) + ylab("Total counts per cell") + ggtitle("Distribution of library sizes") + theme_minimal() @@ -122,6 +140,7 @@ compareSCESets <- function(sces) { colour = "Dataset")) + geom_boxplot() + scale_y_continuous(limits = c(0, 100)) + + scale_colour_manual(values = colours) + ylab("Percentage zeros per gene") + ggtitle("Distribution of zeros per gene") + theme_minimal() @@ -131,6 +150,7 @@ compareSCESets <- function(sces) { colour = "Dataset")) + geom_boxplot() + scale_y_continuous(limits = c(0, 100)) + + scale_colour_manual(values = colours) + ylab("Percentage zeros per cell") + ggtitle("Distribution of zeros per cell") + theme_minimal() @@ -138,14 +158,20 @@ compareSCESets <- function(sces) { mean.zeros <- ggplot(fData.all, aes_string(x = "MeanCounts", y = "pct_dropout", colour = "Dataset", fill = "Dataset")) + - geom_point(size = 0.1, alpha = 0.1) + - geom_smooth() + + geom_point(size = point.size, alpha = point.alpha) + scale_x_log10(labels = scales::comma) + + scale_colour_manual(values = colours) + + scale_fill_manual(values = colours) + xlab("Mean count") + ylab("Percentage zeros") + ggtitle("Mean-dropout relationship") + theme_minimal() + if (fits) { + mean.var <- mean.var + geom_smooth() + mean.zeros <- mean.zeros + geom_smooth() + } + comparison <- list(FeatureData = fData.all, PhenoData = pData.all, Plots = list(Means = means, @@ -166,6 +192,10 @@ compareSCESets <- function(sces) { #' #' @param sces named list of SCESet objects to combine and compare. #' @param ref string giving the name of the SCESet to use as the reference +#' @param point.size size of points in scatter plots. +#' @param point.alpha opacity of points in scatter plots. +#' @param fits whether to include fits in scatter plots. +#' @param colours vector of colours to use for each dataset. #' #' @details #' @@ -225,19 +255,31 @@ compareSCESets <- function(sces) { #' names(difference) #' names(difference$Plots) #' @importFrom ggplot2 ggplot aes_string geom_point geom_boxplot xlab ylab -#' ggtitle theme_minimal geom_hline geom_abline +#' ggtitle theme_minimal geom_hline geom_abline scale_colour_manual +#' scale_fill_manual #' @importFrom scater cpm<- #' @export -diffSCESets <- function(sces, ref) { +diffSCESets <- function(sces, ref, point.size = 0.1, point.alpha = 0.1, + fits = TRUE, colours = NULL) { checkmate::assertList(sces, types = "SCESet", any.missing = FALSE, min.len = 2, names = "unique") checkmate::assertString(ref) + checkmate::assertNumber(point.size, finite = TRUE) + checkmate::assertNumber(point.alpha, lower = 0, upper = 1) + checkmate::assertLogical(fits, any.missing = FALSE, len = 1) if (!(ref %in% names(sces))) { stop("'ref' must be the name of an SCESet in 'sces'") } + if (!is.null(colours)) { + checkmate::assertCharacter(colours, any.missing = FALSE, + len = length(sces) - 1) + } else { + colours <- scales::hue_pal()(length(sces)) + } + ref.dim <- dim(sces[[ref]]) for (name in names(sces)) { @@ -314,6 +356,7 @@ diffSCESets <- function(sces, ref) { colour = "Dataset")) + geom_hline(yintercept = 0, colour = "red") + geom_boxplot() + + scale_colour_manual(values = colours) + ylab(expression(paste("Rank difference mean ", log[2], "(CPM + 1)"))) + ggtitle("Difference in mean expression") + theme_minimal() @@ -323,6 +366,7 @@ diffSCESets <- function(sces, ref) { colour = "Dataset")) + geom_hline(yintercept = 0, colour = "red") + geom_boxplot() + + scale_colour_manual(values = colours) + ylab(expression(paste("Rank difference variance ", log[2], "(CPM + 1)"))) + ggtitle("Difference in variance") + @@ -330,9 +374,11 @@ diffSCESets <- function(sces, ref) { mean.var <- ggplot(fData.all, aes_string(x = "exprs_rank", y = "MeanRankVarDiff", - colour = "Dataset")) + + colour = "Dataset", fill = "Dataset")) + geom_hline(yintercept = 0, colour = "red") + - geom_point() + + geom_point(size = point.size, alpha = point.alpha) + + scale_colour_manual(values = colours) + + scale_fill_manual(values = colours) + xlab("Expression rank") + ylab(expression(paste("Difference in variance ", log[2], "(CPM + 1)"))) + @@ -344,6 +390,7 @@ diffSCESets <- function(sces, ref) { colour = "Dataset")) + geom_hline(yintercept = 0, colour = "red") + geom_boxplot() + + scale_colour_manual(values = colours) + ylab(paste("Rank difference libray size")) + ggtitle("Difference in library sizes") + theme_minimal() @@ -353,6 +400,7 @@ diffSCESets <- function(sces, ref) { colour = "Dataset")) + geom_hline(yintercept = 0, colour = "red") + geom_boxplot() + + scale_colour_manual(values = colours) + ylab(paste("Rank difference percentage zeros")) + ggtitle("Difference in zeros per gene") + theme_minimal() @@ -362,15 +410,18 @@ diffSCESets <- function(sces, ref) { colour = "Dataset")) + geom_hline(yintercept = 0, colour = "red") + geom_boxplot() + + scale_colour_manual(values = colours) + ylab(paste("Rank difference percentage zeros")) + ggtitle("Difference in zeros per cell") + theme_minimal() mean.zeros <- ggplot(fData.all, aes_string(x = "exprs_rank", y = "MeanRankZerosDiff", - colour = "Dataset")) + + colour = "Dataset", fill = "Dataset")) + geom_hline(yintercept = 0, colour = "red") + - geom_point() + + geom_point(size = point.size, alpha = point.alpha) + + scale_colour_manual(values = colours) + + scale_fill_manual(values = colours) + xlab("Expression rank") + ylab("Difference in percentage zeros per gene") + ggtitle("Difference in mean-zeros relationship") + @@ -380,7 +431,8 @@ diffSCESets <- function(sces, ref) { aes_string(x = "RefRankMeanLogCPM", y = "MeanLogCPM", colour = "Dataset")) + geom_abline(intercept = 0, slope = 1, colour = "red") + - geom_point() + + geom_point(size = point.size, alpha = point.alpha) + + scale_colour_manual(values = colours) + xlab(expression(paste("Reference mean ", log[2], "(CPM + 1)"))) + ylab(expression(paste("Alternative mean ", log[2], "(CPM + 1)"))) + ggtitle("Ranked means") + @@ -390,7 +442,8 @@ diffSCESets <- function(sces, ref) { aes_string(x = "RefRankVarLogCPM", y = "VarLogCPM", colour = "Dataset")) + geom_abline(intercept = 0, slope = 1, colour = "red") + - geom_point() + + geom_point(size = point.size, alpha = point.alpha) + + scale_colour_manual(values = colours) + xlab(expression(paste("Reference variance ", log[2], "(CPM + 1)"))) + ylab(expression(paste("Alternative variance ", log[2], "(CPM + 1)"))) + ggtitle("Ranked variances") + @@ -400,7 +453,8 @@ diffSCESets <- function(sces, ref) { aes_string(x = "RefRankLibSize", y = "total_counts", colour = "Dataset")) + geom_abline(intercept = 0, slope = 1, colour = "red") + - geom_point() + + geom_point(size = point.size, alpha = point.alpha) + + scale_colour_manual(values = colours) + xlab("Reference library size") + ylab("Alternative library size") + ggtitle("Ranked library sizes") + @@ -410,7 +464,8 @@ diffSCESets <- function(sces, ref) { aes_string(x = "RefRankZeros", y = "pct_dropout", colour = "Dataset")) + geom_abline(intercept = 0, slope = 1, colour = "red") + - geom_point() + + geom_point(size = point.size, alpha = point.alpha) + + scale_colour_manual(values = colours) + xlab("Reference percentage zeros") + ylab("Alternative percentage zeros") + ggtitle("Ranked percentage zeros per gene") + @@ -420,12 +475,18 @@ diffSCESets <- function(sces, ref) { aes_string(x = "RefRankZeros", y = "pct_dropout", colour = "Dataset")) + geom_abline(intercept = 0, slope = 1, colour = "red") + - geom_point() + + geom_point(size = point.size, alpha = point.alpha) + + scale_colour_manual(values = colours) + xlab("Reference percentage zeros") + ylab("Alternative percentage zeros") + ggtitle("Ranked percentage zeros per cell") + theme_minimal() + if (fits) { + mean.var <- mean.var + geom_smooth() + mean.zeros <- mean.zeros + geom_smooth() + } + comparison <- list(Reference = ref.sce, FeatureData = fData.all, PhenoData = pData.all, @@ -444,3 +505,282 @@ diffSCESets <- function(sces, ref) { return(comparison) } + +#' Make comparison panel +#' +#' Combine the plots from \code{compareSCESets} into a single panel. +#' +#' @param comp list returned by \code{\link{compareSCESets}}. +#' @param title title for the panel. +#' @param labels vector of labels for each of the seven plots. +#' +#' @return Combined panel plot +#' +#' @examples +#' \dontrun{ +#' sim1 <- splatSimulate(nGenes = 1000, groupCells = 20) +#' sim2 <- simpleSimulate(nGenes = 1000, nCells = 20) +#' comparison <- compareSCESets(list(Splat = sim1, Simple = sim2)) +#' panel <- makeCompPanel(comparison) +#' } +#' +#' @importFrom ggplot2 theme element_blank +#' @export +makeCompPanel <- function(comp, title = "Comparison", + labels = c("Means", "Variance", + "Mean-variance relationship", + "Library size", "Zeros per gene", + "Zeros per cell", + "Mean-zeros relationship")) { + + if (!requireNamespace("cowplot", quietly = TRUE)) { + stop("The `cowplot` package is required to make panels.") + } + + checkmate::assertList(comp, any.missing = FALSE, len = 3) + checkmate::checkString(title) + checkmate::checkCharacter(labels, len = 7) + + plots <- list(p1 = comp$Plots$Means, p2 = comp$Plots$Variances, + p3 = comp$Plots$MeanVar, p4 = comp$Plots$LibrarySizes, + p5 = comp$Plots$ZerosGene, p6 = comp$Plots$ZerosCell, + p7 = comp$Plots$MeanZeros) + + # Remove titles and legends + for (plot in names(plots)) { + plots[[plot]] <- plots[[plot]] + theme(legend.position = "none", + plot.title = element_blank()) + } + + # Remove x-axis title from some plots + for (plot in paste0("p", c(1, 2, 4, 5, 6))) { + plots[[plot]] <- plots[[plot]] + theme(axis.title.x = element_blank()) + } + + plots$leg <- cowplot::get_legend(plots$p1 + + theme(legend.position = "bottom")) + + panel <- cowplot::ggdraw() + + cowplot::draw_label(title, 0.5, 0.98, + fontface = "bold", size = 18) + + cowplot::draw_label(labels[1], 0.01, 0.95, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p1, 0.0, 0.74, 0.5, 0.20) + + cowplot::draw_label(labels[2], 0.51, 0.95, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p2, 0.5, 0.74, 0.5, 0.20) + + cowplot::draw_label(labels[3], 0.01, 0.70, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p3, 0.0, 0.49, 0.5, 0.20) + + cowplot::draw_label(labels[4], 0.51, 0.70, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p4, 0.5, 0.49, 0.5, 0.20) + + cowplot::draw_label(labels[5], 0.01, 0.45, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p5, 0.0, 0.24, 0.5, 0.20) + + cowplot::draw_label(labels[6], 0.51, 0.45, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p6, 0.5, 0.24, 0.5, 0.20) + + cowplot::draw_label(labels[7], 0.01, 0.21, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p7, 0.0, 0.00, 0.5, 0.20) + + cowplot::draw_plot(plots$leg, 0.5, 0.00, 0.5, 0.20) + + return(panel) +} + + +#' Make difference panel +#' +#' Combine the plots from \code{diffSCESets} into a single panel. +#' +#' @param diff list returned by \code{\link{diffSCESets}}. +#' @param title title for the panel. +#' @param labels vector of labels for each of the seven sections. +#' +#' @return Combined panel plot +#' +#' @examples +#' \dontrun{ +#' sim1 <- splatSimulate(nGenes = 1000, groupCells = 20) +#' sim2 <- simpleSimulate(nGenes = 1000, nCells = 20) +#' difference <- diffSCESets(list(Splat = sim1, Simple = sim2), ref = "Simple") +#' panel <- makeDiffPanel(difference) +#' } +#' +#' @importFrom ggplot2 theme element_blank +#' @export +makeDiffPanel <- function(diff, title = "Difference comparison", + labels = c("Means", "Variance", "Library size", + "Zeros per cell", "Zeros per gene", + "Mean-variance relationship", + "Mean-zeros relationship")) { + + if (!requireNamespace("cowplot", quietly = TRUE)) { + stop("The `cowplot` package is required to make panels.") + } + + checkmate::assertList(diff, any.missing = FALSE, len = 5) + checkmate::checkString(title) + checkmate::checkCharacter(labels, len = 7) + + plots <- list(p1 = diff$Plots$Means, p2 = diff$QQPlots$Means, + p3 = diff$Plots$Variances, p4 = diff$QQPlots$Variances, + p5 = diff$Plots$MeanVar, p6 = diff$Plots$LibrarySizes, + p7 = diff$QQPlots$LibrarySizes, p8 = diff$Plots$ZerosCell, + p9 = diff$QQPlots$ZerosCell, p10 = diff$Plots$ZerosGene, + p11 = diff$QQPlots$ZerosGene, p12 = diff$Plots$MeanZeros) + + # Remove titles and legends + for (plot in names(plots)) { + plots[[plot]] <- plots[[plot]] + theme(legend.position = "none", + plot.title = element_blank()) + } + + # Remove x-axis title from some plots + for (plot in paste0("p", c(1, 3, 6, 8, 10))) { + plots[[plot]] <- plots[[plot]] + theme(axis.title.x = element_blank()) + } + + plots$leg <- cowplot::get_legend(plots$p1 + + theme(legend.position = "bottom")) + + panel <- cowplot::ggdraw() + + cowplot::draw_label(title, 0.5, 0.98, + fontface = "bold", size = 18) + + cowplot::draw_label(labels[1], 0.0, 0.94, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p1, 0.0, 0.64, 0.18, 0.29) + + cowplot::draw_plot(plots$p2, 0.0, 0.32, 0.18, 0.29) + + cowplot::draw_label(labels[2], 0.21, 0.94, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p3, 0.21, 0.64, 0.18, 0.29) + + cowplot::draw_plot(plots$p4, 0.21, 0.32, 0.18, 0.29) + + cowplot::draw_label(labels[6], 0.0, 0.30, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p5, 0.0, 0.0, 0.38, 0.29) + + cowplot::draw_label(labels[3], 0.41, 0.94, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p6, 0.41, 0.64, 0.18, 0.29) + + cowplot::draw_plot(plots$p7, 0.41, 0.32, 0.18, 0.29) + + cowplot::draw_label(labels[4], 0.61, 0.94, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p8, 0.61, 0.64, 0.18, 0.29) + + cowplot::draw_plot(plots$p9, 0.61, 0.32, 0.18, 0.29) + + cowplot::draw_label(labels[7], 0.41, 0.30, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p12, 0.41, 0.0, 0.38, 0.29) + + cowplot::draw_label(labels[5], 0.81, 0.94, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p10, 0.81, 0.64, 0.18, 0.29) + + cowplot::draw_plot(plots$p11, 0.81, 0.32, 0.18, 0.29) + + cowplot::draw_plot(plots$leg, 0.81, 0.0, 0.2, 0.29) + + return(panel) +} + + +#' Make overall panel +#' +#' Combine the plots from \code{compSCESets} and \code{diffSCESets} into a +#' single panel. +#' +#' @param comp list returned by \code{\link{compareSCESets}}. +#' @param diff list returned by \code{\link{diffSCESets}}. +#' @param title title for the panel. +#' @param row.labels vector of labels for each of the seven rows. +#' +#' @return Combined panel plot +#' +#' @examples +#' \dontrun{ +#' sim1 <- splatSimulate(nGenes = 1000, groupCells = 20) +#' sim2 <- simpleSimulate(nGenes = 1000, nCells = 20) +#' comparison <- compSCESets(list(Splat = sim1, Simple = sim2)) +#' difference <- diffSCESets(list(Splat = sim1, Simple = sim2), ref = "Simple") +#' panel <- makeOverallPanel(comparison, difference) +#' } +#' +#' @importFrom ggplot2 theme element_blank +#' @export +makeOverallPanel <- function(comp, diff, title = "Overall comparison", + row.labels = c("Means", "Variance", + "Mean-variance relationship", + "Library size", "Zeros per cell", + "Zeros per gene", + "Mean-zeros relationship")) { + + if (!requireNamespace("cowplot", quietly = TRUE)) { + stop("The `cowplot` package is required to make panels.") + } + + checkmate::assertList(comp, any.missing = FALSE, len = 3) + checkmate::assertList(diff, any.missing = FALSE, len = 5) + checkmate::checkString(title) + checkmate::checkCharacter(row.labels, len = 7) + + plots <- list(p1 = comp$Plots$Means, p2 = diff$Plots$Means, + p3 = diff$QQPlots$Means, p4 = comp$Plots$Variances, + p5 = diff$Plots$Variances, p6 = diff$QQPlots$Variances, + p7 = comp$Plots$MeanVar, p8 = diff$Plots$MeanVar, + p9 = comp$Plots$LibrarySizes, p10 = diff$Plots$LibrarySizes, + p11 = diff$QQPlots$LibrarySizes, p12 = comp$Plots$ZerosCell, + p13 = diff$Plots$ZerosCell, p14 = diff$QQPlots$ZerosCell, + p15 = comp$Plots$ZerosGene, p16 = diff$Plots$ZerosGene, + p17 = diff$QQPlots$ZerosGene, p18 = comp$Plots$MeanZeros, + p19 = diff$Plots$MeanZeros) + + # Remove titles and legends + for (plot in names(plots)) { + plots[[plot]] <- plots[[plot]] + theme(legend.position = "none", + plot.title = element_blank()) + } + + # Remove x-axis title from some plots + for (plot in paste0("p", c(1, 2, 4, 5, 9, 10, 12, 13, 15, 16))) { + plots[[plot]] <- plots[[plot]] + theme(axis.title.x = element_blank()) + } + + plots$leg <- cowplot::get_legend(plots$p1 + + theme(legend.position = "bottom")) + + panel <- cowplot::ggdraw() + + cowplot::draw_label(title, 0.5, 0.995, + fontface = "bold", size = 18) + + cowplot::draw_label(row.labels[1], 0.01, 0.985, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p1, 0.00, 0.86, 0.32, 0.12) + + cowplot::draw_plot(plots$p2, 0.34, 0.86, 0.32, 0.12) + + cowplot::draw_plot(plots$p3, 0.67, 0.86, 0.32, 0.12) + + cowplot::draw_label(row.labels[2], 0.01, 0.845, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p4, 0.00, 0.72, 0.32, 0.12) + + cowplot::draw_plot(plots$p5, 0.34, 0.72, 0.32, 0.12) + + cowplot::draw_plot(plots$p6, 0.67, 0.72, 0.32, 0.12) + + cowplot::draw_label(row.labels[3], 0.01, 0.705, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p7, 0.00, 0.58, 0.49, 0.12) + + cowplot::draw_plot(plots$p8, 0.51, 0.58, 0.49, 0.12) + + cowplot::draw_label(row.labels[4], 0.01, 0.56, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p9, 0.00, 0.44, 0.32, 0.12) + + cowplot::draw_plot(plots$p10, 0.34, 0.44, 0.32, 0.12) + + cowplot::draw_plot(plots$p11, 0.67, 0.44, 0.32, 0.12) + + cowplot::draw_label(row.labels[5], 0.01, 0.425, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p12, 0.00, 0.30, 0.32, 0.12) + + cowplot::draw_plot(plots$p13, 0.34, 0.30, 0.32, 0.12) + + cowplot::draw_plot(plots$p14, 0.67, 0.30, 0.32, 0.12) + + cowplot::draw_label(row.labels[6], 0.01, 0.285, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p15, 0.00, 0.16, 0.32, 0.12) + + cowplot::draw_plot(plots$p16, 0.34, 0.16, 0.32, 0.12) + + cowplot::draw_plot(plots$p17, 0.67, 0.16, 0.32, 0.12) + + cowplot::draw_label(row.labels[7], 0.01, 0.145, + fontface = "bold", hjust = 0, vjust = 0) + + cowplot::draw_plot(plots$p18, 0.00, 0.02, 0.49, 0.12) + + cowplot::draw_plot(plots$p19, 0.51, 0.02, 0.49, 0.12) + + cowplot::draw_plot(plots$leg, 0.00, 0.00, 1.00, 0.02) + + return(panel) +} diff --git a/man/compareSCESets.Rd b/man/compareSCESets.Rd index e0533d3114487674ac807388762d2e1f1c41cb28..9121d6ea357da34aa8cde8008e767731b5a567f4 100644 --- a/man/compareSCESets.Rd +++ b/man/compareSCESets.Rd @@ -4,10 +4,19 @@ \alias{compareSCESets} \title{Compare SCESet objects} \usage{ -compareSCESets(sces) +compareSCESets(sces, point.size = 0.1, point.alpha = 0.1, fits = TRUE, + colours = NULL) } \arguments{ \item{sces}{named list of SCESet objects to combine and compare.} + +\item{point.size}{size of points in scatter plots.} + +\item{point.alpha}{opacity of points in scatter plots.} + +\item{fits}{whether to include fits in scatter plots.} + +\item{colours}{vector of colours to use for each dataset.} } \value{ List containing the combined datasets and plots. diff --git a/man/diffSCESets.Rd b/man/diffSCESets.Rd index 3fc3e60bcb04fb6ca0ed1de07fe9d8439fc48e20..529b43468c8216263c72cbf5ebd1405a7cbf7b55 100644 --- a/man/diffSCESets.Rd +++ b/man/diffSCESets.Rd @@ -4,12 +4,21 @@ \alias{diffSCESets} \title{Diff SCESet objects} \usage{ -diffSCESets(sces, ref) +diffSCESets(sces, ref, point.size = 0.1, point.alpha = 0.1, fits = TRUE, + colours = NULL) } \arguments{ \item{sces}{named list of SCESet objects to combine and compare.} \item{ref}{string giving the name of the SCESet to use as the reference} + +\item{point.size}{size of points in scatter plots.} + +\item{point.alpha}{opacity of points in scatter plots.} + +\item{fits}{whether to include fits in scatter plots.} + +\item{colours}{vector of colours to use for each dataset.} } \value{ List containing the combined datasets and plots. diff --git a/man/makeCompPanel.Rd b/man/makeCompPanel.Rd new file mode 100644 index 0000000000000000000000000000000000000000..1e32fb056211fa791e114c1ffeb0f4d4c46a115e --- /dev/null +++ b/man/makeCompPanel.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/compare.R +\name{makeCompPanel} +\alias{makeCompPanel} +\title{Make comparison panel} +\usage{ +makeCompPanel(comp, title = "Comparison", labels = c("Means", "Variance", + "Mean-variance relationship", "Library size", "Zeros per gene", + "Zeros per cell", "Mean-zeros relationship")) +} +\arguments{ +\item{comp}{list returned by \code{\link{compareSCESets}}.} + +\item{title}{title for the panel.} + +\item{labels}{vector of labels for each of the seven plots.} +} +\value{ +Combined panel plot +} +\description{ +Combine the plots from \code{compareSCESets} into a single panel. +} +\examples{ +\dontrun{ +sim1 <- splatSimulate(nGenes = 1000, groupCells = 20) +sim2 <- simpleSimulate(nGenes = 1000, nCells = 20) +comparison <- compareSCESets(list(Splat = sim1, Simple = sim2)) +panel <- makeCompPanel(comparison) +} + +} diff --git a/man/makeDiffPanel.Rd b/man/makeDiffPanel.Rd new file mode 100644 index 0000000000000000000000000000000000000000..10b6f6ba47b3bdef19146808519aafa823172db1 --- /dev/null +++ b/man/makeDiffPanel.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/compare.R +\name{makeDiffPanel} +\alias{makeDiffPanel} +\title{Make difference panel} +\usage{ +makeDiffPanel(diff, title = "Difference comparison", labels = c("Means", + "Variance", "Library size", "Zeros per cell", "Zeros per gene", + "Mean-variance relationship", "Mean-zeros relationship")) +} +\arguments{ +\item{diff}{list returned by \code{\link{diffSCESets}}.} + +\item{title}{title for the panel.} + +\item{labels}{vector of labels for each of the seven sections.} +} +\value{ +Combined panel plot +} +\description{ +Combine the plots from \code{diffSCESets} into a single panel. +} +\examples{ +\dontrun{ +sim1 <- splatSimulate(nGenes = 1000, groupCells = 20) +sim2 <- simpleSimulate(nGenes = 1000, nCells = 20) +difference <- diffSCESets(list(Splat = sim1, Simple = sim2), ref = "Simple") +panel <- makeDiffPanel(difference) +} + +} diff --git a/man/makeOverallPanel.Rd b/man/makeOverallPanel.Rd new file mode 100644 index 0000000000000000000000000000000000000000..9e97e5cba3364444efea868b4ab2cb9c2d059851 --- /dev/null +++ b/man/makeOverallPanel.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/compare.R +\name{makeOverallPanel} +\alias{makeOverallPanel} +\title{Make overall panel} +\usage{ +makeOverallPanel(comp, diff, title = "Overall comparison", + row.labels = c("Means", "Variance", "Mean-variance relationship", + "Library size", "Zeros per cell", "Zeros per gene", + "Mean-zeros relationship")) +} +\arguments{ +\item{comp}{list returned by \code{\link{compareSCESets}}.} + +\item{diff}{list returned by \code{\link{diffSCESets}}.} + +\item{title}{title for the panel.} + +\item{row.labels}{vector of labels for each of the seven rows.} +} +\value{ +Combined panel plot +} +\description{ +Combine the plots from \code{compSCESets} and \code{diffSCESets} into a +single panel. +} +\examples{ +\dontrun{ +sim1 <- splatSimulate(nGenes = 1000, groupCells = 20) +sim2 <- simpleSimulate(nGenes = 1000, nCells = 20) +comparison <- compSCESets(list(Splat = sim1, Simple = sim2)) +difference <- diffSCESets(list(Splat = sim1, Simple = sim2), ref = "Simple") +panel <- makeOverallPanel(comparison, difference) +} + +} diff --git a/vignettes/splatter.Rmd b/vignettes/splatter.Rmd index 376ba8c104ecb87ddb4e36679b9b77b7e0f573b1..7d728abf8869c5d779c9e7ba950ff7babbe54a78 100644 --- a/vignettes/splatter.Rmd +++ b/vignettes/splatter.Rmd @@ -473,6 +473,30 @@ distributions. difference$QQPlots$Means ``` +## Making panels + +Each of these comparisons makes several plots which can be a lot to look at. To +make this easier, or to produce figures for publications, you can make use of +the functions `makeCompPanel`, `makeDiffPanel` and `makeOverallPanel`. + +These functions combine the plots into a single panel using the `cowplot` +package. The panels can be quite large and hard to view (for example in +RStudio's plot viewer) so it can be better to output the panels and view them +separately. Luckily `cowplot` provides a convenient function for saving the +images. Here are some suggested parameters for outputting each of the panels: + +```{r save-panels, eval = FALSE} +# This code is just an example and is not run +panel <- makeCompPanel(comparison) +cowplot::save_plot("comp_panel.png", panel, nrow = 4, ncol = 3) + +panel <- makeDiffPanel(difference) +cowplot::save_plot("diff_panel.png", panel, nrow = 3, ncol = 5) + +panel <- makeOverallPanel(comparison, difference) +cowplot::save_plot("overall_panel.png", panel, ncol = 4, nrow = 7) +``` + # Session information {-} ```{r sessionInfo}