Heatmap with 2 color bars (fig4a)
(2 emails:
first email: "another heatmap" - Jul 29th 2020
Second email: "heatmap of 'pheno_rg_matrix_reordered' - Aug 4th 2020 - Feb 12th 2021)
(2 emails:
first email: "another heatmap" - Jul 29th 2020
Second email: "heatmap of 'pheno_rg_matrix_reordered' - Aug 4th 2020 - Feb 12th 2021)
Stored on directory: /space/chen-syn01/1/data/cinliu/plots/heatmaps/fig4a
Hi Nini,
Could you help to plot another heatmap directly from this table text file?
Please add two side color bars next to the matrix on the right. The first 12 rows have one side color bar (on the bar to write 'area' and the rest rows have another side color bar (on the bar to write 'thickness'. Can you also put the brain region labels on the right of the matrix only?
maybe the code is something like this?
RowSideColors = c( # grouping row-variables into different colors
rep("paleturquoise4", 12), # area darker turquoise
rep("paleturquoise2", 12)), #thickness lighter turquoise
an example figure (without dendrogram is fine, just heatmap)
Files given: .txt file ready for heat from
#new correlatin plot
rm(list=ls())
library(RColorBrewer)
library("gplots")
Using gplots to make the heatmaps
import the.txt file - it was already heatmap ready
setwd("/Users/niniliu/Desktop/2020lab/ch-email/heatmap/") #update
df = read.table('pheno_rg_matrix_reorder.txt', h=T)
dfMatrix <- data.matrix(df)
col1<-colorRampPalette(c("blue2","white","magenta2"))
I couldn't figure out how to make 2 sidebars appear on the same plot. So my alternative solution was to make 2 of the same heatmap with different side bars, and then just manually cut and assemble the sidebars in powerpoint
heatmap.2() was used to make the heatmaps.
use RowSideColors = c( rep("colorname", number of rows), rep()) to specify the side row's colors
Example below will code for blue 3 in the first 6 rows, and then make red in the next six spaces...etcs :
RowSideColors = c( # grouping row-variables into different colors
rep("blue3", 6), #dark blue
rep("#ef062d", 6), #red
rep("blue", 5), #blue
rep("#e131b5", 3), #pink
rep("blue", 1), #blue
rep("#e131b5", 3)),
par(oma=c(2,0,0,20),xpd=TRUE). parameters of the outside margins we adjusted, and xpd = TRUE, allows us to draw outside plot area
#color side bar 1
png(paste0("1Peng_reordered_phenolowtri_rguptri_matrix.png"),width = 15*300, height = 12*300, res = 300, pointsize = 10)
par(oma=c(2,0,0,20),xpd=TRUE)# xpd allows Draw outside plot area
heatmap.2(dfMatrix,dendrogram ='none', trace = "none",density.info = "none", Colv = NA, Rowv = NA,
labCol = FALSE,cexRow =3, offsetRow=11,breaks=seq(-1, 1, length.out=200.1),
key.title="",key.xlab="", key.par=list(mar=c(4,0,1,2), cex=1.0, cex.lab=2.0, cex.axis=2.0),
col= col1(200),
RowSideColors = c( # grouping row-variables into different colors
rep("paleturquoise4", 12), # area darker turquoise
rep("paleturquoise2", 12)), #thickness
lmat=rbind(c(3,0,0,4,5), c(0,0,2,1,0)), #specifying the bar to be on the right
lhei=c(0.5,4),
lwid=c(0.1,0.1,4,0.25,1))
dev.off()
Color sidebar 2 (the same as 1 except the side bars are colored differently)
#####color side bar 2
png(paste0("2Peng_reordered_phenolowtri_rguptri_matrix.png"),width = 15*300, height = 12*300, res = 300, pointsize = 10)
par(oma=c(2,0,0,20),xpd=TRUE)# xpd allows Draw outside plot area
heatmap.2(dfMatrix,dendrogram ='none', trace = "none",density.info = "none", Colv = NA, Rowv = NA,
labCol = FALSE,cexRow =3, offsetRow=11,breaks=seq(-1, 1, length.out=200.1),
key.title="",key.xlab="", key.par=list(mar=c(4,0,1,2), cex=1.0, cex.lab=2.0, cex.axis=2.0),
col= col1(200),
RowSideColors = c( # grouping row-variables into different colors
rep("blue3", 6), #dark blue
rep("#ef062d", 6), #red
rep("blue", 5), #blue
rep("#e131b5", 3), #pink
rep("blue", 1), #blue
rep("#e131b5", 3)), #pink
lmat=rbind(c(3,0,0,4,5), c(0,0,2,1,0)),
lhei=c(0.5,4),
lwid=c(0.1,0.1,4,0.25,1))
dev.off()
Manually position the images together in powerpoint, and then export.
Can export using export function or using print function and save as PostScripts and then convert to tiff
heatmap.R
#new correlatin plot
rm(list=ls())
library(RColorBrewer)
library("gplots")
setwd("/Users/niniliu/Desktop/2020lab/ch-email/heatmap/") #update
df = read.table('pheno_rg_matrix_reorder.txt', h=T)
dfMatrix <- data.matrix(df)
col1<-colorRampPalette(c("blue2","white","magenta2"))
#color side bar 1
png(paste0("1Peng_reordered_phenolowtri_rguptri_matrix.png"),width = 15*300, height = 12*300, res = 300, pointsize = 10)
par(oma=c(2,0,0,20),xpd=TRUE)# xpd allows Draw outside plot area
heatmap.2(dfMatrix,dendrogram ='none', trace = "none",density.info = "none", Colv = NA, Rowv = NA,
labCol = FALSE,cexRow =3, offsetRow=11,breaks=seq(-1, 1, length.out=200.1),
key.title="",key.xlab="", key.par=list(mar=c(4,0,1,2), cex=1.0, cex.lab=2.0, cex.axis=2.0),
col= col1(200),
RowSideColors = c( # grouping row-variables into different colors
rep("paleturquoise4", 12), # area darker turquoise
rep("paleturquoise2", 12)), #thickness
lmat=rbind(c(3,0,0,4,5), c(0,0,2,1,0)), #specifying the bar to be on the right
lhei=c(0.5,4),
lwid=c(0.1,0.1,4,0.25,1))
dev.off()
#####color side bar 2
png(paste0("2Peng_reordered_phenolowtri_rguptri_matrix.png"),width = 15*300, height = 12*300, res = 300, pointsize = 10)
par(oma=c(2,0,0,20),xpd=TRUE)# xpd allows Draw outside plot area
heatmap.2(dfMatrix,dendrogram ='none', trace = "none",density.info = "none", Colv = NA, Rowv = NA,
labCol = FALSE,cexRow =3, offsetRow=11,breaks=seq(-1, 1, length.out=200.1),
key.title="",key.xlab="", key.par=list(mar=c(4,0,1,2), cex=1.0, cex.lab=2.0, cex.axis=2.0),
col= col1(200),
RowSideColors = c( # grouping row-variables into different colors
rep("blue3", 6), #dark blue
rep("#ef062d", 6), #red
rep("blue", 5), #blue
rep("#e131b5", 3), #pink
rep("blue", 1), #blue
rep("#e131b5", 3)), #pink
lmat=rbind(c(3,0,0,4,5), c(0,0,2,1,0)),
lhei=c(0.5,4),
lwid=c(0.1,0.1,4,0.25,1))
dev.off()