Skip to content

Commit

Permalink
improve the count plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
cdiener committed Jan 24, 2024
1 parent 16584bd commit 733ee09
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
#' @export
#' @importFrom ggplot2 ggplot geom_boxplot facet_wrap scale_y_log10 xlab
plot_counts <- function(ps, variable, tax_level = "genus", taxa = NULL,
normalized = TRUE, pc = 0.5, only_data = FALSE) {
dts <- taxa_count(ps, lev = tax_level)
normalized = TRUE, pc = 0.5, only_data = FALSE,
zeros = TRUE) {
dts <- taxa_count(ps, lev = tax_level, zeros = zeros)
valid_taxa <- taxa
if (normalized) {
dts <- normalize(dts)
Expand All @@ -42,15 +43,15 @@ plot_counts <- function(ps, variable, tax_level = "genus", taxa = NULL,

if (is.integer(dts$value) || is.factor(dts$value)) {
pl <- ggplot(dts, aes(x = value, y = reads + pc, group = value)) +
geom_boxplot(outlier.color = NA) +
geom_jitter(width = 0.2, alpha = 0.5, size = 1, stroke = 0) +
geom_boxplot(outlier.color = NA, width = 0.1) +
geom_jitter(width = 0.3, alpha = 0.5, size = 1, stroke = 0) +
facet_wrap(~ taxa) + scale_y_log10() +
xlab(variable)
labs(x = variable, y = "normalized reads")
} else {
pl <- ggplot(dts, aes(x = value, y = reads + pc)) +
geom_point(alpha = 0.5, stroke = 0) +
geom_point(alpha = 1, stroke = 0) +
facet_wrap(~ taxa) + scale_y_log10() +
xlab(variable)
labs(x = variable, y = "normalized reads")
}

return(pl)
Expand Down

0 comments on commit 733ee09

Please sign in to comment.