How to determine width of heatmap
1
0
Entering edit mode
5.7 years ago
luzglongoria ▴ 50

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

pheatmap label_row heatmap • 5.5k views
ADD COMMENT
2
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

luzglongoria ,did you try my solution?

ADD REPLY
0
Entering edit mode

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 REPLY
2
Entering edit mode
5.7 years ago

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 COMMENT
0
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 2049 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