i can plot heat-map but i have issue with annotation i want to annotate rows and column so i have genes
Chemokines genes
CXCL1
CXCL2
CXCL3
CXCL5
CXCL6
CXCL8
CXCL10
CCl20
CCl22
CCl28
TNF related genes
TNFAIP2
TNFAIP3
TNFRSF11A
TNFRSF14
TNFRSF1B
TNFRSF25
TNFSF10
TNFSF13
TNFSF13B
TNFSF15
TNFSF9
INTERLEUKIN AND RELATED GENES
IL36G
IL17C
IL1B
IL1A
IL11RA
1L32
1L17RD
IL36RN
IL20RA
IL23A
IL4I1
IL2RG
IL15
1L20RB
IL15RA
IL17RC
library(gplots)
file1<- read.csv('data.csv',header = T)
class(file1)
dat <- data.frame(file1)
dim(dat)
names(dat)
head(dat)
rownames(dat) <-dat$gene
head(dat)
dim(dat)
head(dat)
dat.tdy <- dat[,2:7]
dat.n <- scale(t(dat.tdy))
dat.tn <- t(dat.n)
round(colMeans(dat.n),1)
apply(dat.n,2,sd)
d1 <- dist(dat.n,method = "euclidean", diag = FALSE, upper = FALSE)
d2 <- distdat.tn,method = "euclidean", diag = FALSE, upper = TRUE)
c1 <- hclust(d1, method = "complete", members = NULL)
c2 <- hclust(d2, method = "complete", members = NULL)
macolor = colorRampPalette(c("navyblue", "white", "red"))(100)
heatmap.2dat.tn,Rowv=as.dendrogram(c2),Colv = as.dendrogram(c1),col =macolor
,scale="row", margin=c(6, 4),trace='none',
symkey=FALSE,symbreaks=FALSE,dendrogram="both",
density.info='density', denscol="red",lhei=c(1,3),cexRow = 1,cexCol = 1,
lwid=c(.9,3), keysize=0.1, key.par = list(cex=0.5))
The code above I have two condition control+salmonella and KD+salmonella ,
I want to annotate my row as such
Chemokines genes TNF related genes INTERLEUKIN AND RELATED GENES
similarly i want to annotate my column as control+salmonella KD+salmonella ,
I saw the manual with the car data set but its confusing im not able to do it..
My issue is i have a create a annotation data frame for row specific genes as and the based on the condition which is column specific
Any suggestion or help would be highly appreciated.
thanks a ton as always ...is it possible to label those row and column annotation as text legend ...?because in the code you defined it but someone looking at it would find it difficult to interpret ,how to add the text or as make a legend to show the annotation ?
my heatmap
Yes, of course, you can add custom legends with:
For the position (first parameter), you can specify top, left, bottom, right, or X Y co-ordinates (2 parameters).
It may take a while to correctly position the legend. The positioning works in conjunction with:
mar
parameter topar()
(outside ofheatmap.2
)margin
parameter toheatmap.2
okay.. ..let me use it ...
My friend, I would additionally encourage you to take a look at ComplexHeatmap, where manipulating the heatmap annotations is much more flexible than other heatmap packages. I have posted some initial starter code here:
C: how to cluster genes in heatmap
well because my PI need heatmap with Z score so thats is the reason why im using heatmap.2
You can convert any data-matrix to Z-scores outside of the heatmap.2 function. If you do this, however, then you must set
scale=FALSE
inside the heatmap.2 funtionokay...I think complex heatmap is really rich as compared to heatmap.2 and pheatmap so i can make the data matrix into Z score and then pass it on to the complex heatmap....that is what you are suggesting ?
i will use your code from the link you have given ...for sure...
i can do the same for row side annotation? isn't it?
Yes, you can technically create any legend that you want.
For example:
thank...you....very much...
Okay, make sure that you take some time off over Christmas (if you celebrate Christmas)
same to you, i mean every time i ask a question you are the one to come up with solution that's Christmas for me
Good to hear. All I can say is that hard work pays off