Ali*_*Ali 7 r heatmap density-plot ggally
这是上一个问题的编辑版本.
我们给予米的ñ表ñ意见(样本)在米变量(基因等),我们期待学习每对观测的变量的行为-例如两个观察具有最高正或负相关.为此,我在Stadler et.al看到了一张很棒的图表.自然科学(2011):

这里它可以是要使用的样本数据集.
m <- 1000
samples <- data.frame(unif1 = runif(m), unif2 = runif(m, 1, 2), norm1 = rnorm(m),
norm2 = rnorm(m, 1), norm3 = rnorm(m, 0, 5))
Run Code Online (Sandbox Code Playgroud)
我已经测试gpairs(samples)了gpairs产生这个的包装.这是一个好的开始,但没有选择在右上部分放置相关系数,也没有选择在下角的密度图:

接下来我使用ggparis(samples, lower=list(continuous="density"))了包GGally(感谢@LucianoSelzer以下评论).现在我们在上角和下角的密度上有相关性,但我们缺少对角线条形图,密度图不是热图形状.

任何想法,使更接近所需的图片(第一个)?
您可以尝试组合几种不同的绘图方法并合并结果.这是一个例子,可以相应调整:
cors<-round(cor(samples),2) #correlations
# make layout for plot layout
laymat<-diag(1:5) #histograms
laymat[upper.tri(laymat)]<-6:15 #correlations
laymat[lower.tri(laymat)]<-16:25 #heatmaps
layout(laymat) #define layout using laymat
par(mar=c(2,2,2,2)) #define marginals etc.
# Draw histograms, tweak arguments of hist to make nicer figures
for(i in 1:5)
hist(samples[,i],main=names(samples)[i])
# Write correlations to upper diagonal part of the graph
# Again, tweak accordingly
for(i in 1:4)
for(j in (i+1):5){
plot(-1:1,-1:1, type = "n",xlab="",ylab="",xaxt="n",yaxt="n")
text(x=0,y=0,labels=paste(cors[i,j]),cex=2)
}
# Plot heatmaps, here I use kde2d function for density estimation
# image function for generating heatmaps
library(MASS)
for(i in 2:5)
for(j in 1:(i-1)){
k <- kde2d(samples[,i],samples[,j])
image(k,col=heat.colors(1000))
}
Run Code Online (Sandbox Code Playgroud)
编辑:修正了最后一个循环的索引.
