1

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:

enter image description here

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
Xinting WANG
  • 1,905
  • 2
  • 15
  • 20
  • Can you provide a sample data set and what you'd like to show? It should be straightforward to brute force a plot drawing rectangles and triangles in the absence of something more elegant. – DaveTurek May 13 '15 at 12:22
  • @DaveTurek Thanks a lot. I just added a sample dataset. – Xinting WANG May 13 '15 at 15:11

1 Answers1

2

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).

DaveTurek
  • 1,297
  • 7
  • 8
  • Thanks very much Dave. This really helps. I used your method and implemented it using ggplot2 and successfully plotted it. – Xinting WANG May 16 '15 at 12:11