creating a heatmap with R and retrieve cluster data from dendogram
2
1
Entering edit mode
3.4 years ago

Dear all I have drug resistance profile of 100 bacterial genomes. The data is like

Antibiotic name  ab1 ab2 ab3 ab4 ab5
genome1 S R S R S
genome2 R S S R
genome3 R S S R


I want to generate a R plot. the code for generating a R plot is like:

data <- read.csv("/Users/apple/Desktop/heatmap.csv", sep=",")
rnames <- data[,1]
mat_data <- data.matrix(data[,2:ncol(data)])
rownames(mat_data) <- rnames
my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299)
col_breaks = c(seq(-1,0,length=100), # for red
+ seq(0,0.8,length=100),  # for yellow
+ seq(0.81,1,length=100)) # for green

install.packages("gplots")
heatmap.2(mat_data,
+ main = "Drug Resistance profile",
+ notecol="red",
+ density.info="none",
+ trace="none",
+ margins = c(20,15),
+ col=my_palette,
+ dendogram="row",
+ Colv="NA")


but this code produces a very dense margin on rows labels. Can anyone tell me how to modify this plot to make it visualize to all. also tell me how can I change the color of the plot as well as is there other way to represent this data like how to represent data in a circular way in a heatmap.

R • 3.0k views
0
Entering edit mode

Add the heatmap image so that we can actually see the issue

0
Entering edit mode

1
Entering edit mode
3.4 years ago

The 'dense' margin appears because your margin sizes are enormous through the following parameter: margins = c(20,15) In any normal situation, this should only be margins=c(5,5)

To represent this as a circular dendrogram, look here: A: how to draw circular dendrogram with distance information

For other 'circular' ideas and for how to colour various dendrogram branches, take a look at the dendextend package: Introduction to dendextend

For extracting cluster information from either heatmap.2 or pheatmap, take a look here: A: extract dendrogram cluster from pheatmap

1
Entering edit mode
3.4 years ago
EagleEye 6.9k

For extracting clusters from generated heatmap/dendogram check this previous post.