目录
superheat
superheat热图用于生成和自定义热图, 散点图,箱形图,条形图,折线图和箱形图可以与热图的列和行相邻绘制,从而增加了一层信息。
# plot a heatmap of the numerical iris variables
# cluster by species and plot Sepal.Length on the right
# save the superheat object to access the membership vectors
sh <- superheat(X = iris[,-c(1, 5)],
yr = iris[,1],
yr.axis.name = "Sepal.Length",
membership.rows = iris$Species)
sh$membership.rows
superheat(mtcars,
# normalize variables
scale = T,
# order rows/cols based on heirarchical clustering
pretty.order.rows = TRUE,
pretty.order.cols = TRUE,
# plot miles per gallon next to the rows
yr = mtcars$mpg,
yr.axis.name = "miles per gallon",
# plot correlation with mpg above columns
yt = cor(mtcars)[, "mpg"],
yt.plot.type = "bar",
yt.axis.name = "correlation with mpg",
# increase size of left labels
left.label.size = 0.45)
heatmap.2
可以绘制颜色差别明显的热图,并将颜色键中的对称点从0更改为1,具体可以用
library(gplots)
x = matrix(sample(seq(-1,3,by=.1),100,replace=TRUE),ncol=10)
# plot. We want -1 to 0.8 being red, 0.8 to 1.2 being black, 1.2 to 3 being green.
heatmap.2(x, col=redgreen, breaks=c(-1,0.8,1.2,3))
Pheatmap
绘制以特定点为对称点的colorbar
bk <- c(seq(0.6,0.9,by=0.01),seq(1.0,1.4,by=0.01)) #设置不对称colorbar
library(pheatmap)
pheatmap(t(value), scale="none",cluster_row =T,cluster_cols = T,
display_numbers = sig.mat,
color = c(colorRampPalette(colors = c("blue","white"))(length(bk)/2),colorRampPalette(colors = c("white","red"))(length(bk)/2)),
angle_col = c('45'),
border=FALSE,
breaks = bk)
绘制颜色对比鲜明的热图时,breaks变换一下
pheatmap(t(value), scale="none",cluster_row =T,cluster_cols = T,
display_numbers = sig.mat,
color = c(colorRampPalette(colors = c("green","black"))(length(bk)/2),colorRampPalette(colors = c("black","red"))(length(bk)/2)),
# color=colorRampPalette(c("green","black","red"))(length(bk)),
angle_col = c('45'),
border=FALSE,
breaks = bk)
只展示三种颜色
pheatmap(t(value), scale="none",cluster_row =T,cluster_cols = T,
display_numbers = sig.mat,
color=colorRampPalette(c("green","black","red"))(3),
angle_col = c('45'),
border=FALSE,
breaks = c(0.6,0.95,1.05,1.4))
Ref:
https://www.it1352.com/533253.html