diff --git a/R/lefser.R b/R/lefser.R index 22b7225..0684b6f 100644 --- a/R/lefser.R +++ b/R/lefser.R @@ -264,6 +264,7 @@ lefser <- } group <- .numeric01(groupf) groups <- 0:1 + names(groups) <- groupsf expr_data <- assay(expr, i = assay) expr_sub <- filterKruskal(expr = expr_data, group = group, p.value = kruskal.threshold) @@ -315,5 +316,8 @@ lefser <- scores_df <- .trunc(scores_df, trim.names) threshold_scores <- abs(scores_df$scores) >= lda.threshold - scores_df[threshold_scores, ] + res_scores <- scores_df[threshold_scores, ] + class(res_scores) <- c("lefser_df", class(res_scores)) + attr(res_scores, "groups") <- groups + res_scores } diff --git a/R/lefserPlot.R b/R/lefserPlot.R index ce34ac6..e3c64f6 100644 --- a/R/lefserPlot.R +++ b/R/lefserPlot.R @@ -28,7 +28,15 @@ utils::globalVariables(c("Names", "scores")) lefserPlot <- function(df, colors = c("red", "forestgreen"), trim.names = TRUE) { df <- .trunc(df, trim.names) - group <- ifelse(df$scores > 0, 1, 0) + groups <- attr(df, "groups") + if (is.null(groups)) + group <- ifelse(df$scores > 0, 1, 0) + else + group <- ifelse( + df$scores > 0, + names(groups)[groups == 1], + names(groups)[groups == 0] + ) df$group <- as.factor(group) plt <- ggplot(df, aes(reorder(Names, scores), scores)) + ylab("LDA SCORE (log 10)") +