Well, here's one way using ggplot
.
library(reshape2) # for melt
library(RColorBrewer) # for brewer.pal(...)
library(ggplot2)
x <- cbind(id=as.numeric(rownames(x)),x)
gg <- melt(x,id="id")
gg$variable <- as.numeric(substr(gg$variable,2,4))
brks <- c(0,10^rep(0:7))
gg$bin <- cut(gg$value,breaks=brks,labels=0:7,include.lowest=T)
ggplot(gg) +
geom_tile(aes(x=factor(id),y=factor(10-variable),fill=bin))+
scale_fill_manual(name="",labels=brks,values=rev(brewer.pal(8,"Spectral")))+
scale_y_discrete(labels=10:0)+
labs(x="",y="")+
theme_bw()+theme(panel.border=element_blank())
The basic idea is to use a logarithmic scale for the colors. This is a bit of a problem for you because you have zeros. So a work-around sets bins using the cut(...)
function. The bin breaks are set to 0,1,10,100,...,1e7.
Your data is in "wide" format: different values of "y" in different columns, whereas ggplot
needs the data in "long" format: all the data in one column with x-values and y-values in separate columns. We convert wide to long using the melt(...)
function. The rest of the code sets up the bins and the labels, and formats the plot to make it look as close to yours as I could manage.