pathway_heatmap {ggpicrust2}R Documentation

Create pathway heatmap

Description

This function creates a heatmap of the predicted functional pathway abundance data. The function first makes the abundance data relative, then converts the abundance data to a long format and orders the samples based on the environment information. The heatmap is then created using the 'ggplot2' library. The color palette, appearance and the color bar of the heatmap can be customized using the 'scale_fill_gradientn', 'theme' and 'guides' functions respectively.

Arguments

abundance

A matrix or data frame of pathway abundance data, where columns correspond to samples and rows correspond to pathways.

metadata

A data frame of metadata, where each row corresponds to a sample and each column corresponds to a metadata variable.

group

A character string specifying the column name in the metadata data frame that contains the group variable.

Value

A ggplot heatmap object. The output is a ggplot object representing the heatmap of the predicted functional pathway abundance data. The heatmap visualizes the z score of pathways in different samples.

Examples


library(ggpicrust2)
library(ggh4x)
library(dplyr)
library(tidyr)
library(tibble)
library(magrittr)
# Create example functional pathway abundance data
kegg_abundance_example <- matrix(rnorm(30), nrow = 3, ncol = 10)
colnames(kegg_abundance_example) <- paste0("Sample", 1:10)
rownames(kegg_abundance_example) <- c("PathwayA", "PathwayB", "PathwayC")

# Create example metadata
# Please ensure the sample IDs in the metadata have the column name "sample_name"
metadata_example <- data.frame(sample_name = colnames(kegg_abundance_example),
                               group = factor(rep(c("Control", "Treatment"), each = 5)))

# Create a heatmap
pathway_heatmap(kegg_abundance_example, metadata_example, "group")
# Use real dataset
data("metacyc_abundance")
data("metadata")
metacyc_daa_results_df <- pathway_daa(abundance = metacyc_abundance %>%
column_to_rownames("pathway"),
metadata = metadata, group = "Environment", daa_method = "LinDA")
annotated_metacyc_daa_results_df <- pathway_annotation(pathway = "MetaCyc",
daa_results_df = metacyc_daa_results_df, ko_to_kegg = FALSE)
feature_with_p_0.05 <- metacyc_daa_results_df %>% filter(p_adjust < 0.05)
pathway_heatmap(abundance = metacyc_abundance %>%
right_join(annotated_metacyc_daa_results_df %>%
select(all_of(c("feature","description"))), by = c("pathway" = "feature")) %>%
filter(pathway %in% feature_with_p_0.05$feature) %>%
select(-"pathway") %>%
column_to_rownames("description"), metadata = metadata, group = "Environment")


[Package ggpicrust2 version 1.7.3 Index]