Reputation: 13
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.
Upvotes: 0
Views: 7884
Reputation: 15123
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")
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)
Third way is using d3heatmap
. You may install this package manually in github and details of this function, see d3heatmap.
Upvotes: 1