Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
seraidarian committed Aug 2, 2024
1 parent 153df32 commit 157e549
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Imports:
ggnewscale,
viridis,
tibble,
tidytext,
tidytree,
tidygraph,
rlang,
Expand All @@ -69,7 +70,8 @@ Suggests:
vegan,
bluster,
ComplexHeatmap,
circlize
circlize,
topicmodels
Remotes:
github::microbiome/miaTime
Roxygen: list(markdown = TRUE)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ importFrom(tidygraph,as_tbl_graph)
importFrom(tidygraph,as_tibble)
importFrom(tidyr,drop_na)
importFrom(tidyr,pivot_longer)
importFrom(tidytext,reorder_within)
importFrom(tidytext,scale_y_reordered)
importFrom(tidytree,as.phylo)
importFrom(tidytree,as.treedata)
Expand Down
32 changes: 16 additions & 16 deletions R/plotLoadings.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
#'
#' @details
#'
#' Inspired by the \code{\link[diffTop:plotASVcircular]{plotASVcircular}} method using phyloseq
#' Inspired by the \code{plotASVcircular} method using phyloseq
#' and has been converted to use TreeSummarizedExperiment/SingleCellExperiment objects.
#'
#' TreeSummarizedExperiment/SingleCellExperiment objects are expected to have content in reducedDim slot.
#' It is impossible to add tree if only the matrix is given. Number of features must be reduced
#' before calling function or it will not be understandable. For example
Expand Down Expand Up @@ -68,21 +67,21 @@
#' tse <- runPCA(tse, ncomponents = 5, assay.type = "clr")
#' plotLoadings(tse, dimred = "PCA", layout = "heatmap", add.tree = TRUE)
#'
#' # Plotting without tree as a heatmap
#' loadings_matrix <- attr(reducedDim(tse, "PCA"), "rotation")
#' plotLoadings(loadings_matrix, dimred = "PCA", layout = "heatmap")
#'
#' # Plotting without tree as a barplot
#' plotLoadings(loadings_matrix, dimred = "PCA")
#' loadings_matrix <- attr(reducedDim(tse, "PCA"), "rotation")
#' plotLoadings(loadings_matrix)
#'
#' # Plotting more features
#' plotLoadings(loadings_matrix, n = 12, dimred = "PCA")
#'
#' plotLoadings(loadings_matrix, n = 12)
#'
#' # Plotting without tree as a heatmap
#' plotLoadings(loadings_matrix, layout = "heatmap")
#'
#' # Plotting with less components
#' tse <- runPCA(tse, ncomponents = 4, assay.type = "clr")
#' loadings_matrix <- attr(reducedDim(tse, "PCA"), "rotation")
#' plotLoadings(loadings_matrix, dimred = "PCA", ncomponents = 4)
#'
#' plotLoadings(loadings_matrix, ncomponents = 4)
#'
#' # Plotting if loadings matrix name has been changed
#' tse <- runPCA(tse, name = "myPCAmatrix", ncomponents = 5, assay.type = "clr")
#' plotLoadings(tse, dimred = "myPCAmatrix")
Expand All @@ -91,7 +90,8 @@
#' tse <- runPCA(tse, ncomponents = 5, assay.type = "clr")
#' plotLoadings(tse, dimred = "PCA", layout = "heatmap", add.tree = TRUE, rank = "Phylum")
#'
#' # Plotting after performing LDA method
#' # Plotting after performing LDA
#' library(topicmodels)
#' tse <- addLDA(tse)
#' plotLoadings(tse, dimred = "LDA", ncomponents = 2)
NULL
Expand Down Expand Up @@ -173,12 +173,12 @@ setMethod("plotLoadings", signature = c(x = "matrix"),

# Plot features with heatmap layout
if (layout == "heatmap") {
p <- ComplexHeatmap::Heatmap(loadings_matrix, heatmap_legend_param = list(title = "Value"))
p <- ComplexHeatmap::Heatmap(x, heatmap_legend_param = list(title = "Value"))
} else {
# Ordering loadings and adding factor to keep the order
df <- .get_loadings_plot_data(x, n, ncomponents)
# Plot features with barplot layout
p <- .barplot_feature_loadings(df, layout, n, ncomponents)
p <- .barplot_feature_loadings(df)
}
return(p)
}
Expand Down Expand Up @@ -219,7 +219,7 @@ setMethod("plotLoadings", signature = c(x = "SingleCellExperiment"),
# Ordering loadings and adding factor to keep the order
df <- .get_loadings_plot_data(loadings_matrix, n, ncomponents)
# Plot features with barplot layout
p <- .barplot_feature_loadings(df, layout, n, ncomponents)
p <- .barplot_feature_loadings(df)
}
return(p)
}
Expand Down Expand Up @@ -393,7 +393,7 @@ setMethod("plotLoadings", signature = c(x = "SingleCellExperiment"),
return(p)
}

#' @importFrom tidytext scale_y_reordered
#' @importFrom tidytext scale_y_reordered reorder_within
.barplot_feature_loadings <- function(df) {
cnames <- unique(df$PC)
p <- ggplot(df, aes(x = Value, y = reorder_within(Feature, Value, PC))) +
Expand Down
20 changes: 10 additions & 10 deletions man/plotLoadings.Rd

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

0 comments on commit 157e549

Please sign in to comment.