Skip to content

Commit

Permalink
Support box plot in addition to violin plot
Browse files Browse the repository at this point in the history
  • Loading branch information
TuomasBorman committed Jun 3, 2024
1 parent c6f5a13 commit 5779a67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
9 changes: 6 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ Authors@R: c(
person("Alan", "O'Callaghan", role=c("ctb", "cre"), email="[email protected]"),
person("Yun", "Peng", role=c("ctb"), email="[email protected]"),
person("Leo", "Lahti", role=c("ctb"), email="[email protected]",
comment = c(ORCID = "0000-0001-5537-637X"))
comment = c(ORCID = "0000-0001-5537-637X")),
person("Tuomas", "Borman", role = c("ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-8563-8884"))
)
Version: 1.31.2
Date: 2024-01-28
Version: 1.31.3
Date: 2024-06-03
License: GPL-3
Title: Single-Cell Analysis Toolkit for Gene Expression Data in R
Description: A collection of tools for doing various analyses of
Expand Down
19 changes: 16 additions & 3 deletions R/plot_central.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#' \item{\code{jitter_type}:}{String to define how points are to be jittered in a violin plot.
#' This is either with random jitter on the x-axis (\code{"jitter"}) or in a \dQuote{beeswarm} style (if \code{"swarm"}, default).
#' The latter usually looks more attractive, but for datasets with a large number of cells, or for dense plots, the jitter option may work better.}
#' \item{\code{layout}:}{String to define layout of plot. Must be \code{"violin"} (violin plot, default) or \code{"box"} (box plot).}
#' }
#'
#' @section Distributional calculations:
Expand Down Expand Up @@ -63,15 +64,15 @@ NULL
#' @importFrom ggbeeswarm geom_quasirandom
#' @importFrom ggplot2 ggplot geom_violin xlab ylab stat_summary geom_jitter
#' position_jitter coord_flip geom_point stat_smooth geom_tile theme_bw theme
#' geom_bin2d geom_hex stat_summary_2d stat_summary_hex
#' geom_bin2d geom_hex stat_summary_2d stat_summary_hex geom_boxplot
.central_plotter <- function(object, xlab = NULL, ylab = NULL,
colour_by = NULL, shape_by = NULL, size_by = NULL, fill_by = NULL,
show_median = FALSE, show_violin = TRUE, show_smooth = FALSE, show_se = TRUE,
# show_points = TRUE,
theme_size = 10, point_alpha = 0.6, point_size = NULL, point_shape = 19, add_legend = TRUE,
point_FUN = NULL, jitter_type = "swarm",
rasterise = FALSE, scattermore = FALSE, bins = NULL,
summary_fun = "sum", hex = FALSE)
summary_fun = "sum", hex = FALSE, layout = "violin")
# Internal ggplot-creating function to plot anything that involves points.
# Creates either a scatter plot, (horizontal) violin plots, or a rectangle plot.
{
Expand All @@ -90,7 +91,7 @@ NULL
# Adding violins.
plot_out <- ggplot(object, aes(x=.data$X, y=.data$Y)) +
xlab(xlab) + ylab(ylab)
if (show_violin) {
if (show_violin && layout == "violin") {
if (is.null(fill_by)) {
viol_args <- list(fill="grey90")
} else {
Expand All @@ -101,6 +102,18 @@ NULL
geom_violin,
c(viol_args, list(colour = "gray60", alpha = 0.2, scale = "width", width = 0.8))
)
} else if (layout == "box") {
# User can choose also to plot box plot instaed of violin plot
if (is.null(fill_by)) {
box_args <- list(fill="grey90")
} else {
box_args <- list(mapping=aes(fill=.data[[fill_by]]))
}
plot_out <- plot_out +
do.call(
geom_boxplot,
c(box_args, list(colour = "black", alpha = 0.2))
)
}

# Adding median, if requested.
Expand Down
1 change: 1 addition & 0 deletions man/scater-plot-args.Rd

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

0 comments on commit 5779a67

Please sign in to comment.