Question: How to determine width of heatmap
0
gravatar for luzglongoria
7 months ago by
luzglongoria20
luzglongoria20 wrote:

Hi there,

I have almost done with my heatmap but I cannot figure out how to modify the command in order to see the label. Please, see below:

## Import dataset
data <- read.table("Genes_with_function.txt", header = TRUE, sep = "\t", dec = ".")
mat_data <- data.matrix(data[,2:ncol(data)])

# transform to Z-scale
mat <- t(scale(t(data.matrix(mat_data))))

# set colour
myCol <- colorRampPalette(c("#f03b20", "#fff7bc", "#2c7fb8"))(100)
myBreaks <- seq(-2, 3, length.out=100)

# For ID
ID <- read.table("ID.txt", header = TRUE, sep = "\t", dec = ".")  ### a new .txt file with only the ID of the genes

# Do the plot
hmap <- pheatmap(mat,
             cluster_rows = TRUE,
             cluster_cols = TRUE,
             scale = 'none',
             breaks = myBreaks,
             col = myCol,
             show_colnames = TRUE,
             labels_row = ID$ID)

Then I get this heatmap: https://ibb.co/nzMMy5t

As you can see the names of the genes (TRINITY blahblah) is imposible to see. Is there any way of specify that?

By the way the ID file looks like this:

https://ibb.co/Scxr2S0

Thank you in advance

heatmap pheatmap label_row • 316 views
ADD COMMENTlink modified 7 months ago by lakhujanivijay4.6k • written 7 months ago by luzglongoria20
2

You could modify the value of the width parameter that is passed to pheatmap(). Also, why not get rid of the 'TRINITY' prefix of the rownames? - it is not needed. You could also consider replacing the first _ with \n via:

sub('_', '\n', x)
ADD REPLYlink written 7 months ago by Kevin Blighe51k

Thank you much!

It worked with the commands cellwidth cellheight

But still the legend is over the text:

https://ibb.co/wr3jjrL

Any idea how to move to the left (for instance)?

ADD REPLYlink modified 7 months ago • written 7 months ago by luzglongoria20

I am not sure why it is doing that. I use cellwidth and it comfortably positions the legend after the labels, no matter how long are the labels.

ADD REPLYlink written 7 months ago by Kevin Blighe51k

Even without specifying width or cellwidth, my version of pheatmap correctly positions the colour bar:

data <- replicate(25, rnorm(40))
rownames(data) <- paste("Floccinaucinihilipilification_LooongGeneName", c(1:nrow(data)))
colnames(data) <- paste("Sample", c(1:ncol(data)))

pheatmap(data, 
    show_rownames=T,
    cluster_cols=T,
    cluster_rows=T,
    scale="row",
    clustering_distance_rows="euclidean",
    clustering_distance_cols="euclidean",
    clustering_method="complete",
    border_color=FALSE,
    cex=1.0)

d

Which version are you using? - I am using pheatmap_1.0.12 (R 3.5.3)

ADD REPLYlink modified 7 months ago • written 7 months ago by Kevin Blighe51k

I am using the same version as you.

Maybe the problem is that I am using two different files and pheatmap does not recognize them?

ADD REPLYlink written 7 months ago by luzglongoria20

luzglongoria ,did you try my solution?

ADD REPLYlink written 7 months ago by lakhujanivijay4.6k

I had assumed that s/he did try, but then I received a comment to my own comment (above). luzglongoria, can you confirm? - bioExplorer's solution should be good.

ADD REPLYlink written 7 months ago by Kevin Blighe51k
2
gravatar for lakhujanivijay
7 months ago by
lakhujanivijay4.6k
India
lakhujanivijay4.6k wrote:

Try this code and adjust the width parameter inside the png function, i.e. try changing width = 3100 to what is suitable to you until you see full name

## Import dataset
data <- read.table("Genes_with_function.txt", header = TRUE, sep = "\t", dec = ".")
mat_data <- data.matrix(data[,2:ncol(data)])

# transform to Z-scale
mat <- t(scale(t(data.matrix(mat_data))))

# set colour
myCol <- colorRampPalette(c("#f03b20", "#fff7bc", "#2c7fb8"))(100)
myBreaks <- seq(-2, 3, length.out=100)

# For ID
ID <- read.table("ID.txt", header = TRUE, sep = "\t", dec = ".")   

### a new .txt file with only the ID of the genes

png("heatmap.png", width=3100,height=2000, res=315, pointsize=12)

pheatmap(mat, color=colorRampPalette(c("red","yellow","grey","blue","green"))(60), cluster_cols=TRUE, cluster_rows = TRUE,              
scale = 'none', breaks = myBreaks, col = myCol, show_colnames = TRUE, labels_row = ID$ID)

dev.off()
ADD COMMENTlink written 7 months ago by lakhujanivijay4.6k

Thank you for the comment. I used those commands and I got the same problem. Finally , I used the command cellwidth cellheight and it worked very well.

ADD REPLYlink written 7 months ago by luzglongoria20
Please log in to add an answer.

Help
Access

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