Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 7 additions & 13 deletions R/plotAbundance.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@
#' 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
#' 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")}
Expand Down Expand Up @@ -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
#'
Expand Down Expand Up @@ -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
Expand Down
16 changes: 5 additions & 11 deletions man/plotAbundance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-2plotAbundance.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions vignettes/miaViz.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading