Has anyone tried absence or presence heatmap ? (Or suggestion)
1
0
Entering edit mode
25 days ago
ohtang7 ▴ 40

I have this kind of data (0=absence, 1=presence) with 4 groups, 21 samples as below.

enter image description here

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 !!

R absence Heatmap grouping • 475 views
ADD COMMENT
0
Entering edit mode

Just FYI, rows are 4 groups and columns are 21 samples.

ADD REPLY
2
Entering edit mode
24 days ago
KABILAN ▴ 130
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.

ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

Welcome. You can check the ComplexHeatmap manual in https://github.com/jokergoo/ComplexHeatmap.

ADD REPLY

Login before adding your answer.

Traffic: 1898 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6