What a nice suggestion ! I will try to use ComplexHeatmap library to conduct it. I didn't even know the package. Thank you very much.
Has anyone tried absence or presence heatmap ? (Or suggestion)
I have this kind of data (0=absence, 1=presence) with 4 groups, 21 samples as below.
As appeared in the excel, the 1 could appear as the color that represent the group (presence), how can I draw that information in heatmap using R ?
If anyone has similar experience of visualization, please leave me any recommendation for it.
- Maybe there could be better way to represent the group and presence of the taxa in each samples with visualization.
Any code or comment for the heatmap visualization would be greatly appreciated !!
• 1,806 views
•
link
1 answer
library(ComplexHeatmap)
df1 <- df[,-2] #Change 'df' into your respective dataset
rownames(df1) <- df1$Index
df1 <- df1[,-1]
# Define a color scheme for binary data (0 and 1)
binary_colors <- c("0" = "blue", "1" = "red")
# Create the heatmap
Heatmap(as.matrix(df1),
name = "Presence",
col = binary_colors,
column_title = "Samples",
row_title = "Taxa",
show_column_names = TRUE,
show_row_names = FALSE,
cluster_columns = FALSE, # Disable clustering for clarity
cluster_rows = FALSE) # Disable clustering for clarity
You can try this R script. Change df into your respective dataset.
• 0 views
•
link
• 0 views
•
link
Welcome. You can check the ComplexHeatmap manual in https://github.com/jokergoo/ComplexHeatmap.
• 0 views
•
link
Log in to answer this question.
Just FYI, rows are 4 groups and columns are 21 samples.