0

I generated heatmap in R with my gene expression (TPM) csv data. Here are codes I used.

> library(ggplot2)
> library(tidyverse)
> exp.data<-read.csv(file="C:/R/Bulk-seq_DEG.csv")
> head(exp.data)
> rownames(exp.data) <- exp.data$Gene_Symbol
> exp.data_matrix <- as.matrix(exp.data[2:4])
> head(exp.data_matrix)
> heatmap(exp.data_matrix, Rowv=NA, Colv=NA, scale="row")

And I finally got the heatmap below. After that, I am trying to present color scale bar on my heatmap, but it didn't work.

  1. How can I add color scale bar on my heatmap?? I need a help!
  2. Also, How can I present the total gene names on the heatmap?

enter image description here

Park
  • 14,771
  • 6
  • 10
  • 29
Juhee
  • 3
  • 2
  • 5
  • It would be very helpful to solve your question if you provide some [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of your data. – Park Sep 17 '21 at 01:23

1 Answers1

1

Since there isn't any sample data provided, the code I wrote may quite different with your data or not applicable. I'll use data datasets::mtcars to make some example code.

Before we get started, let's look at data's variable type first to apply to your case more easier. To make heatmap, it would be better to look at type of scale(mtcars). I'll let dummy as scale(mtcars).

dummy <- scale(mtcars)
str(dummy)

num [1:32, 1:11] 0.151 0.151 0.45 0.217 -0.231 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:32] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710" "Hornet 4 Drive" ...
  ..$ : chr [1:11] "mpg" "cyl" "disp" "hp" ...
 - attr(*, "scaled:center")= Named num [1:11] 20.09 6.19 230.72 146.69 3.6 ...
  ..- attr(*, "names")= chr [1:11] "mpg" "cyl" "disp" "hp" ...
 - attr(*, "scaled:scale")= Named num [1:11] 6.027 1.786 123.939 68.563 0.535 ...
  ..- attr(*, "names")= chr [1:11] "mpg" "cyl" "disp" "hp" ...

As you see, guessing with your heatmap, Mazda RX4, and etc are similar type with Gbp2, and etc. And cyl,... match with ?OS's.

For the first question, to add color scale bar, there are several methods using other packages. First way is using gplot::heatmap.2.

gplots::heatmap.2(dummy, scale = "none", col = bluered(100), 
                  trace = "none", density.info = "none")

gplot

Second way is using pheatmap::pheatmap. It will plot clustered heatmap. For more information, see pheatmap. You may add many arguments on your purpose.

pheatmap::pheatmap(dummy)

pheatmap

Third way is using d3heatmap. You may install this package manually in github and details of this function, see d3heatmap.

Park
  • 14,771
  • 6
  • 10
  • 29