Question

I'm trying to join different type of data in the same heatmap plot. But I need to use different set of colors for each of the sub-data. Here is an example:

data1 = matrix(c(1:9),nrow=3)
color1 = colorRampPalette(c('red','blue'))(max(data1))
data2 = matrix(sample(c(0:1),12, replace=T),nrow=3)
color2 = colorRampPalette(c('black','white'))(max(data2)+1) # +1 because it starts in 0
data = cbind(data1,data2)
# I want to join the following two images
image(t(data1),col=color1)
image(t(data2),col=color2)

The result should have the first 3 columns (from data1) in colors red/blue, and from the 4th to the end columns should be in black/white. I can transform data matrix into a colors matix if this helps. I tried heatmap(), but seem to work with just one set of colors. In the example, the 1 from data1 should be plotted red, but from the data2 should be plotted white. Thanks!

Était-ce utile?

La solution

You cannot use the same color index twice. However, you can work around this by adding a suitable offset to the elements of data2 and concatenate the data and colors as follows:

image(t(cbind(data1,data2+length(data1)+1)), col=c(color1, color2))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top