Skip to content

Commit

Permalink
include groups in lefserPlot, refers to #15
Browse files Browse the repository at this point in the history
  • Loading branch information
LiNk-NY committed Sep 6, 2023
1 parent 8114c16 commit e2b90fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion R/lefser.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
10 changes: 9 additions & 1 deletion R/lefserPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)") +
Expand Down

0 comments on commit e2b90fd

Please sign in to comment.