Question: creating a heatmap with R and retrieve cluster data from dendogram
gravatar for sharmatina189059
5 weeks ago by
United States
sharmatina18905910 wrote:

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

+ main = "Drug Resistance profile",
+ notecol="red",
+ 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 • 171 views
ADD COMMENTlink modified 4 weeks ago by EagleEye4.9k • written 5 weeks ago by sharmatina18905910

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

ADD REPLYlink written 5 weeks ago by Vijay Lakhujani1.6k

Please tell me how to upload pic in this forum

ADD REPLYlink written 5 weeks ago by sharmatina18905910
gravatar for Kevin Blighe
5 weeks ago by
Kevin Blighe11k
Kevin Blighe11k wrote:

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

ADD COMMENTlink modified 5 weeks ago • written 5 weeks ago by Kevin Blighe11k
gravatar for EagleEye
4 weeks ago by
EagleEye4.9k wrote:

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

ADD COMMENTlink written 4 weeks ago by EagleEye4.9k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 822 users visited in the last hour