Comments (13)
Hi,
Based on the images you've shared, it seems like there might be an issue with the code you ran. It appears that all the cells in the heatmap are approximately the same color, indicating that there's no range represented.
It's possible that you haven't set the sample.id in the metadata to be the sample_name, which could be causing this problem. I would suggest checking that to see if it helps.
library(ggpicrust2)
library(tidyverse)
abundance_matrix <- read.csv("~/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/hharder1/abundance_matrix.csv", sep="")
metadata <- read.delim("~/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/hharder1/metadata.txt")
metadata$sample_name <- metadata$sample.id
rownames(abundance_matrix) <- metadata$sample.id
abundance_matrix <- t(abundance_matrix)
ggpicrust2::pathway_heatmap(abundance_matrix, metadata, "Txt")
However, I don't think it's a good idea to directly plot a heatmap for such a large matrix. Instead, you may want to focus on only plotting the pathways that have statistical significance in the pathway analysis, or you can identify the pathways that you are interested in and plot only those.
I hope this helps. Let me know if you have any further questions.
Best regards,
Chen YANG
from ggpicrust2.
What is the best way to filter the heatmap to only show the significant pathways?
from ggpicrust2.
library(ggpicrust2)
library(tidyverse)
abundance_matrix <- read.csv("~/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/hharder1/abundance_matrix.csv", sep="")
metadata <- read.delim("~/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/hharder1/metadata.txt")
metadata$sample_name <- metadata$sample.id
rownames(abundance_matrix) <- metadata$sample.id
daa_results_df <- pathway_daa(...)
abundance_matrix_sub <- abundance_matrix[colnames(abundance_matrix) %in% daa_results_df[daa_results_df$p.adjust <= 0.05,]$feature, ]
abundance_matrix_sub <- t(abundance_matrix_sub)
ggpicrust2::pathway_heatmap(abundance_matrix_sub, metadata, "Txt")
from ggpicrust2.
Hello again Chen Yang,
Thank you for all your help the other day. I am pretty new to R and am still struggling with my heatmap. These commands produce a good heatmap, but I am wondering how I can get labels for the sample names, with the samples grouped by experimental treatment (pre_post_intervention) with a color coded legend bar on the bottom (per the example on your main page).
Your continued help is greatly appreciated, thank you! Nate
kegg_abundance <- ko2kegg_abundance(file = "pred_metagenome_unstrat.tsv")
metadata <-
read_delim(
"QIIME_map_comp4_prePostOnly.txt",
delim = "\t",
escape_double = FALSE,
trim_ws = TRUE
)
metadata2 <- as.data.frame(metadata) %>%
rename(sample_name = `#SampleID`)
heatmap_plot <- pathway_heatmap(kegg_abundance, metadata2, "pre_post_intervention")
print(heatmap_plot)
## filtered heatmap
sig_Welch <- daa_results_df[daa_results_df$p_adjust <= 0.0001 & daa_results_df$method == "ALDEx2_Welch's t test", ]$feature
# Use the selected pathways to filter the abundance matrix
kegg_abundance_sig <- kegg_abundance[sig_Welch, ]
heatmap_plot2 <- ggpicrust2::pathway_heatmap(kegg_abundance_sig, metadata2, "pre_post_intervention")
daa_results_df.txt
pred_metagenome_unstrat.txt
QIIME_map_comp4_prePostOnly.txt
from ggpicrust2.
Hello @Nathanielhubert ,
Adding a color label to the bottom of heatmap is a beta function. It can't work stablely so I am still modifing it. I would release the new version with the renewed heatmap. Now you can use image editing software such as Photoshop or Illustrator to add labels to the heatmap.
Best regards,
Chen YANG
from ggpicrust2.
Thank you, Chen Yang,
I was able to get labels using the code below, but it is difficult to be sure the labels are correctly aligned with the data in part because the heatmap is plotting z-scores and I have a table of kegg_abundance.
In hopes of ensuring the correct order of data, I put my metadata and kegg_abundance tables in the same order that I wanted the heatmap plot to show (I was finding the order of the labels may not align correctly if you try re-sorting in R).
Is it possible to plot the abundance data (or log abundance or log relative abundance, whatever is most appropriate) rather than z-score?
I am also running into a scale issue with the z-score legend as the legend only labels values 0.2, 0.4, 0.6, 0.8 which is a very narrow range, smushed together in the middle of the minimum and maximum values. Is there any way to fix that? Is z-score the most appropriate value to be plotting?
Thank you again for your help! Nate
`library(readr)
library(ggpicrust2)
library(tidyverse)
library(patchwork)
library(ggprism)
library(dplyr)
kegg_abundance <- ko2kegg_abundance(file = "pred_metagenome_unstrat.tsv")
metadata <-
read_delim(
"metadata.txt",
delim = "\t",
escape_double = FALSE,
trim_ws = TRUE
)
metadata2 <- as.data.frame(metadata) %>%
rename(sample_name = sample_name
)
group <-
"pre_post_intervention"
# Create a heatmap
heatmap_plot <- pathway_heatmap(t(kegg_abundance), metadata2, "pre_post_intervention")
heatmap_plot <- heatmap_plot +
scale_x_discrete(labels = rownames(kegg_abundance)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
print(heatmap_plot)
ggsave("picrust_heatmap.pdf", plot = heatmap_plot, width = 10, height = 40)`
from ggpicrust2.
Hello @Nathanielhubert ,
You can achieve the desired result by using the following code:
library(readr)
library(ggpicrust2)
library(tidyverse)
library(patchwork)
library(ggprism)
# Update to the latest version
devtools::install_github("cafferychen777/ggpicrust2")
daa_Welchs_results_0001_df_annotated <- read.delim("~/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/Nathanielhubert/daa_Welchs_results_0001_df_annotated.txt")
kegg_abundance <- read.delim("~/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/Nathanielhubert/kegg_abundance.txt", row.names = 1)
metadata <- read_delim("Nathanielhubert/QIIME_map_comp4_prePostOnly.txt", delim = "\t", escape_double = FALSE, trim_ws = TRUE)
daa_Welchs_results_0001_df_annotated$p_adjust <- round(daa_Welchs_results_0001_df_annotated$p_adjust, 5)
daa_Welchs_results_0001_df_annotated <- daa_Welchs_results_0001_df_annotated[!is.na(daa_Welchs_results_0001_df_annotated$pathway_name),]
p <- pathway_errorbar(
abundance = kegg_abundance,
daa_results_df = daa_Welchs_results_0001_df_annotated,
Group = metadata$pre_post_intervention,
p_values_threshold = 0.0001,
order = "pathway_class",
select = NULL,
ko_to_kegg = TRUE,
p_value_bar = TRUE,
colors = NULL,
x_lab = "pathway_name"
)
metadata2 <- metadata %>% rename(sample_name = `#SampleID`)
group <- "pre_post_intervention"
# Create a heatmap
heatmap_plot <- ggpicrust2::pathway_heatmap(abundance = kegg_abundance, metadata = metadata2, group = "pre_post_intervention")
heatmap_plot <- heatmap_plot +
scale_x_discrete(labels = levels(heatmap_plot$data$Sample)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
print(heatmap_plot)
ggsave("picrust_heatmap.pdf", plot = heatmap_plot, width = 10, height = 40)
Please make sure to update to the latest version by running the following command before executing the code:
devtools::install_github("cafferychen777/ggpicrust2")
Feel free to modify the code as per your requirements. Let me know if you need any further assistance!
from ggpicrust2.
Hi again, If you look at the two attached heatmaps here, the z-score patterns are the same but the order of the samples is different - labels must be wrong in one of them. Is there a way to know the labels are right? Do you have to plot z-score or can you plot the abundance patterns?
picrust_heatmap 4.18.21 PM.pdf
picrust_heatmap_pre_next_to_post.pdf
from ggpicrust2.
Also, the legend is not very informative
from ggpicrust2.
If you are using heatmap_plot +
scale_x_discrete(labels = levels(heatmap_plot$data$Sample)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)), the plot will be right. Because the levels(heatmap_plot$data$Sample determine the order of x axis of heatmap.
from ggpicrust2.
The code inside pathway_heatmap automatically attaches same group level together.
from ggpicrust2.
Hello @Nathanielhubert ,
I just update ggpicrust2 and I think the new function will help you. Now you don't need to add a label manually.
# # Create a heatmap
heatmap_plot <- pathway_heatmap(abundance = kegg_abundance[daa_Welchs_results_0001_df_annotated$feature,], metadata = metadata2, group = "pre_post_intervention")
pathway_heatmap(abundance = kegg_abundance %>% rownames_to_column("feature") %>% right_join(daa_Welchs_results_0001_df_annotated %>% select(all_of(c("feature","pathway_name"))), by = "feature") %>% column_to_rownames("pathway_name") %>% select(-all_of("feature")), metadata = metadata2, group = "pre_post_intervention")
Best Regards,
from ggpicrust2.
from ggpicrust2.
Related Issues (20)
- error with MicrobiomeStat HOT 5
- Error in `guide_transform()`: ! <Guide> classes have been rewritten as <ggproto> classes. HOT 3
- undefined columns selected and ‘round’ not meaningful for factors HOT 3
- How to obtain log-fold change values? HOT 3
- curl_fetch_memory HOT 4
- The 'method' column in the 'daa_results_df' data frame contains more than one method. HOT 2
- All my pathway results are NA
- Help needed using sample dada Math.factor ‘round’ not meaningful for factors HOT 2
- pathway_pca HOT 4
- pathway_errorbar no longer working to graph data
- Is this package compatible with other ggplot functions?
- Error pathway_errorbar "`$<-.data.frame`(`*tmp*`, "group", value = c(2L, 2L, 2L, 2L, : replacement has 20 rows, data has 1" HOT 2
- Error in switch(file_format, .txt = abundance <- readr::read_delim(file, : EXPR must be a length 1 vector**
- pathway_heatmap cannot reorder HOT 1
- Error from pathway_errorbar HOT 1
- add a title to errorbar and heatmap HOT 9
- Installation issues with Rfast HOT 2
- Issue with pathway_errorbar : "The `legend.text.align` theme element is not defined in the element hierarchy." HOT 6
- Error in ggpicrust2 (There are no statistically significant biomarkers in the dataset) HOT 4
- Error in `plot_theme()`: ! The `legend.text.align` theme element is not defined in the element hierarchy. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggpicrust2.