diff --git a/DESCRIPTION b/DESCRIPTION index f5afd928..bfa52d17 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: miaViz Title: Microbiome Analysis Plotting and Visualization -Version: 1.21.4 +Version: 1.21.5 Authors@R: c(person(given = "Tuomas", family = "Borman", role = c("aut", "cre"), email = "tuomas.v.borman@utu.fi", diff --git a/R/plotAbundance.R b/R/plotAbundance.R index 66290806..11610458 100644 --- a/R/plotAbundance.R +++ b/R/plotAbundance.R @@ -64,7 +64,7 @@ #' plot be spitted into facets? (Default: \code{FALSE}) #' #' \item \code{facet.cols}: \code{Logical scalar}. Should the columns in the -#' plot be spitted into facets? (Default: \code{FALSE}) +#' plot be spitted into facets? (Default: \code{TRUE}) #' #' \item \code{ncol}: \code{Numeric scalar}. if facets are applied, #' \code{ncol} defines many columns should be for plotting the different @@ -72,7 +72,7 @@ #' #' \item \code{scales} \code{Character scalar}. Defines the behavior of the #' scales of each facet. The value is passed into -#' \code{\link[ggplot2:facet_wrap]{facet_wrap}}. (Default: \code{"fixed"}) +#' \code{\link[ggplot2:facet_wrap]{facet_wrap}}. (Default: \code{"free_x"}) #' } #' See \code{\link{mia-plot-args}} for more details i.e. call #' \code{help("mia-plot-args")} @@ -123,19 +123,13 @@ #' plot <- plotAbundance( #' tse, assay.type = "relabundance", group = "Phylum", #' col.var = "SampleType") -#' \donttest{ -#' # These two plots can be combined with wrap_plots function from patchwork -#' # package -#' library(patchwork) -#' wrap_plots(plot, ncol = 1, heights = c(0.95, 0.05)) -#' } #' -#' # Same plot as above but showing sample IDs as labels for the x axis on the -#' # top plot. Moreover, we use facets. +#' # Create a plot with sample grouping, and showing sample IDs as labels for +#' # the x axis on the top plot. #' plot <- plotAbundance( #' tse, assay.type = "relabundance", #' group = "Phylum", col.var = "SampleType", add.legend = FALSE, -#' add.x.text = TRUE, facet.cols = TRUE, scales = "free_x") + +#' add.x.text = TRUE) + #' theme(axis.text.x = element_text(angle = 90)) #' plot #' @@ -557,8 +551,8 @@ setMethod("plotAbundance", signature = c("SummarizedExperiment"), function( #' @importFrom stats formula .abund_plotter_incorporate_metadata <- function( plot_out, df, col.var = features, features = NULL, - facet.cols = FALSE, facet.rows = one.facet, - one.facet = one_facet, one_facet = FALSE, ncol = 2, scales = "fixed", + facet.cols = TRUE, facet.rows = one.facet, + one.facet = one_facet, one_facet = FALSE, ncol = 2, scales = "free_x", ...){ # To disable "no visible binding for global variable" message in cmdcheck X <- NULL diff --git a/man/plotAbundance.Rd b/man/plotAbundance.Rd index 6a6444bf..d48ee599 100644 --- a/man/plotAbundance.Rd +++ b/man/plotAbundance.Rd @@ -62,7 +62,7 @@ decreasing or increasing fashion? (Default: \code{FALSE}) plot be spitted into facets? (Default: \code{FALSE}) \item \code{facet.cols}: \code{Logical scalar}. Should the columns in the -plot be spitted into facets? (Default: \code{FALSE}) +plot be spitted into facets? (Default: \code{TRUE}) \item \code{ncol}: \code{Numeric scalar}. if facets are applied, \code{ncol} defines many columns should be for plotting the different @@ -70,7 +70,7 @@ facets. (Default: \code{2}) \item \code{scales} \code{Character scalar}. Defines the behavior of the scales of each facet. The value is passed into -\code{\link[ggplot2:facet_wrap]{facet_wrap}}. (Default: \code{"fixed"}) +\code{\link[ggplot2:facet_wrap]{facet_wrap}}. (Default: \code{"free_x"}) } See \code{\link{mia-plot-args}} for more details i.e. call \code{help("mia-plot-args")}} @@ -139,19 +139,13 @@ plotAbundance( plot <- plotAbundance( tse, assay.type = "relabundance", group = "Phylum", col.var = "SampleType") -\donttest{ -# These two plots can be combined with wrap_plots function from patchwork -# package -library(patchwork) -wrap_plots(plot, ncol = 1, heights = c(0.95, 0.05)) -} -# Same plot as above but showing sample IDs as labels for the x axis on the -# top plot. Moreover, we use facets. +# Create a plot with sample grouping, and showing sample IDs as labels for +# the x axis on the top plot. plot <- plotAbundance( tse, assay.type = "relabundance", group = "Phylum", col.var = "SampleType", add.legend = FALSE, - add.x.text = TRUE, facet.cols = TRUE, scales = "free_x") + + add.x.text = TRUE) + theme(axis.text.x = element_text(angle = 90)) plot diff --git a/tests/testthat/test-2plotAbundance.R b/tests/testthat/test-2plotAbundance.R index c84a1943..8e7e2b20 100644 --- a/tests/testthat/test-2plotAbundance.R +++ b/tests/testthat/test-2plotAbundance.R @@ -38,7 +38,7 @@ test_that("plot abundance", { expect_true(all(c("colour_by","X","Y") %in% colnames(plot$data))) plot <- plotAbundance( x, assay.type = "counts", group = "Phylum", col.var = "SampleType", - order.col.by = "SampleType") + order.col.by = "SampleType", facet.cols = FALSE) expect_true(is.list(plot)) expect_s3_class(plot[[1]],"ggplot") # Check that the grouping is correct @@ -47,7 +47,7 @@ test_that("plot abundance", { rowData(x)$Salame <- sample(letters[1:5], nrow(x), replace=TRUE) plot <- plotAbundance( x, assay.type="counts", group = "Salame", col.var = "SampleType", - order.col.by = "SampleType") + order.col.by = "SampleType", facet.cols = FALSE) expect_true(is.list(plot)) expect_s3_class(plot[[1]],"ggplot") # Expect error since too many rows diff --git a/vignettes/miaViz.Rmd b/vignettes/miaViz.Rmd index aa5903d8..4fbbf407 100644 --- a/vignettes/miaViz.Rmd +++ b/vignettes/miaViz.Rmd @@ -92,18 +92,15 @@ plotAbundance( ``` The `features` argument is reused for plotting data along the different samples. -In the next example the ~SampleType~ is plotted along the samples. In this case -the result is a list, which can combined using external tools, for example -`patchwork`. +In the next example the ~SampleType~ is plotted along the samples. ```{r plotabundance_sampletype} -library(patchwork) -plots <- plotAbundance( +plotAbundance( GlobalPatterns[rowData(GlobalPatterns)$Phylum %in% prev_phylum], features = "SampleType", rank = "Phylum", - assay.type = "relabundance") -plots$abundance / plots$SampleType + plot_layout(heights = c(9, 1)) + assay.type = "relabundance" +) ``` Further example about composition barplot can be found at Orchestrating