问题描述
我在《自然方法》中遇到了这篇文章,该文章提供了一个非常好的热图: http://www.nature.com/nmeth/journal/v12/n4/full/nmeth.3311.html
与其他热图不同的是,每个矩形均由对角线分隔,其中一部分代表文献数据,另一部分代表内部数据.我认为这是比较数据的一种非常好的方法.但是,我不知道如何在R中绘制这张照片.有人对此有任何线索吗?
下面提供了一个小屏幕截图:
下面是2 * 2网格的演示数据集.我想要按组划分的四个矩形的颜色.
Para1 Para2值组A D 0.2 A1A E 0.4 A1B D 0.56 A1B E 0.32 A1A D 0.7 B1A E 0.16 B1B D 0.12 B1B E 0.71 B1
在 heatmap
或 lattice :: levelplot
中,我看不到任何精美的东西.也许有人知道 ggplot
中的方式.
这是蛮力的概念证明:
d = data.frame(p1 = rep(LETTERS [1:2],times = 2,each = 2),p2 = rep(LETTERS [4:5],times = 4),值= c(.2,.4,.56,.32,.7,.16,.12,.71),group = rep(c("A1","B1"),each = 4))x = as.numeric(d $ p1)y = as.numeric(d $ p2)plot(1,xlim = c(1,length(unique(x))+ 1),ylim = c(1,length(unique(y))+ 1),type ="n",bty ="n",xaxt ="n",yaxt ="n",xlab =",ylab =")for(i in 1:nrow(d)){if(d $ group [i] =="A1")多边形(x [i] + c(0,1,1),y [i] + c(0,0,1),col =灰色(d $值[i]))if(d $ group [i] =="B1")多边形(x [i] + c(0,1,0),y [i] + c(0,1,1),col =灰色(d $值[i]))}axis(1,at = sort(unique(x))+.5,labels = levels(d $ p1),lty = 0)axis(2,at = sort(unique(y))+.5,labels = levels(d $ p2),lty = 0)
您可能想要添加一个色阶,并使用比我的 value
映射到 gray
的阴影更鲜艳的颜色(值越暗)./p>
I came across this article on Nature Methods which provided a very nice heatmap:http://www.nature.com/nmeth/journal/v12/n4/full/nmeth.3311.html
Different from other heat map is each rectangle is divided by a diagonal line, with 1 part represent the literature data and the other in-house data. I think this is a very nice way to compare the data. However, I do not know how to draw this pic in R. Does anyone have any clue on how to do this?
A small screenshot is provided below:
Below is a demo dataset of a 2*2 grid. I would like the colour of the four rectagles divided by Group.
Para1 Para2 Value Group
A D 0.2 A1
A E 0.4 A1
B D 0.56 A1
B E 0.32 A1
A D 0.7 B1
A E 0.16 B1
B D 0.12 B1
B E 0.71 B1
I don't see anything elegant in heatmap
or lattice::levelplot
. Maybe someone knows how in ggplot
.
Here is a brute force proof-of-concept:
d=data.frame(p1=rep(LETTERS[1:2],times=2,each=2),
p2=rep(LETTERS[4:5],times=4),
value=c(.2,.4,.56,.32,.7,.16,.12,.71),
group=rep(c("A1","B1"),each=4))
x=as.numeric(d$p1)
y=as.numeric(d$p2)
plot(1,xlim=c(1,length(unique(x))+1),ylim=c(1,length(unique(y))+1),
type="n",bty="n",xaxt="n",yaxt="n",xlab="",ylab="")
for(i in 1:nrow(d)) {
if(d$group[i]=="A1") polygon(x[i]+c(0,1,1),y[i]+c(0,0,1),col=gray(d$value[i]))
if(d$group[i]=="B1") polygon(x[i]+c(0,1,0),y[i]+c(0,1,1),col=gray(d$value[i]))
}
axis(1,at=sort(unique(x))+.5,labels=levels(d$p1),lty=0)
axis(2,at=sort(unique(y))+.5,labels=levels(d$p2),lty=0)
You'd probably want to add a color scale, and use something more colorful than my mapping of value
to shades of gray
(lower values are darker).
这篇关于R:如何绘制热图除以对角线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!