Skip to content
Snippets Groups Projects

update

Merged Etienne Rifa requested to merge bars_update into master
5 files
+ 59
3
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 28
1
@@ -31,6 +31,32 @@ rarefaction <- function(data = data, col = NULL, step = 100, ggplotly = TRUE){
}
#' aggregate_top_taxa from microbiome package
#'
#'
#' @param x phyloseq object
#' @param top Keep the top-n taxa, and merge the rest under the category 'Other'. Instead of top-n numeric this can also be a character vector listing the groups to combine.
#' @param level Summarization level (from ‘rank_names(pseq)’)
#'
#' @importFrom microbiome aggregate_taxa
#' @importFrom microbiome top_taxa
#'
#' @export
aggregate_top_taxa <- function (x, top, level){
x <- aggregate_taxa(x, level)
tops <- top_taxa(x, top)
tax <- tax_table(x)
inds <- which(!rownames(tax) %in% tops)
tax[inds, level] <- "Other"
tax_table(x) <- tax
tt <- tax_table(x)[, level]
tax_table(x) <- tax_table(tt)
aggregate_taxa(x, level)
}
#' Barplots plotly
#'
#'
@@ -48,7 +74,6 @@ rarefaction <- function(data = data, col = NULL, step = 100, ggplotly = TRUE){
#' @return Returns barplots in an interactive plotly community plot
#'
#' @import plotly
#' @importFrom microbiome aggregate_top_taxa
#' @importFrom reshape2 melt
#' @importFrom gtools mixedsort
#' @importFrom dplyr group_map group_by across
@@ -75,6 +100,8 @@ if( all(Ord1 != sample_variables(data)) | all(Fact1 != sample_variables(data))){
Fdata = data
psobj.top <- aggregate_top_taxa(Fdata, rank, top = top)
# print("get data")
sdata <- as.data.frame(sample_data(psobj.top), stringsAsFactors = TRUE)
# sdata$sample.id = sample_names(psobj.top)
Loading