I wrote this function (borrowing heavily from an example from Longhow Lam)

heatplot = function(x,y,z,bgcol="#777044",coltype='heat', ccex = 1.5,
circles=TRUE, ...){
        #browser()
        layout(matrix(c(1, 2, 3), nc=3), widths=c(7, 1, .5))
        ## create the scatterplot withdifferent colors
        #ccols = heat.colors(length(z))
        ColFormula1 = paste(coltype, '.colors(length(z))', sep='')
        ccols = eval(parse(text=ColFormula1))
        bgfun=function(){
                tmp = par("usr")
                rect(tmp[1], tmp[3], tmp[2], tmp[4], col=bgcol)
                ylimits=par()$usr[c(3,4)]
                abline(h=pretty(ylimits,10), lty=2, col='black')
        }
        scale = function(x){(x-min(x))/diff(range(x))}
        xname = deparse(substitute(x))
        yname = deparse(substitute(y))
        zname = deparse(substitute(z))
        plot(x, y, pch=16, col=ccols[rank(z)], panel.first=bgfun(),
                        xlab=xname,ylab=yname, cex=ccex ,...)
        if(circles){
                points(x, y, cex=ccex)
        }

        zlim = range(z, finite=TRUE)
        lvs = pretty(zlim, 20)

        plot.new()
        mtext(paste('legend for "', zname, '" values', sep=''), side=2)
        plot.window(xlim=c(0, 1), ylim=range(lvs), xaxs="i", yaxs="i")
        points(1,1,cex=5)
        #rect(0, lvs[-length(lvs)],1, lvs[-1],
        #                col=heat.colors(length(lvs)-1))
        ColFormula2 = paste(coltype, '.colors(length(lvs)-1)', sep='')
        rect(.1, lvs[-length(lvs)],1, lvs[-1],
                        col=eval(parse(text=ColFormula2)))
        axis(4)
        layout(c(1))
}

## Examples:
x = 1:100
y = sin(x/50) + rnorm(100)/20
z = sort(rnorm(100))
heatplot(x,y,z)
heatplot(x,y,z, ccex=5)
heatplot(x,y,z, ccex=5, circles=F)
heatplot(x,y,z, ccex=5, circles=F, coltype='cm')
heatplot(x,y,z, ccex=5, circles=F, coltype='topo', bgcol='lavender',
        main='Something Special')




On Tue, Sep 6, 2011 at 2:14 PM, Jinrui Xu <jinruixu@umich.edu> wrote:

> Hi Sarah,
>
> To me, the heatmap function calculates "density value"  for each grid of
> the heatmap automatically from the input matrix. In my case, I already got
> the "density value" as a vector, say Z. I want to plot a heat map with x and
> y as is axsis and z values as the "density" of grid. I am not familiar with
> R code, so I am writting to ask how to. Thanks!
>
> jinrui,
>
>
> Quoting Sarah Goslee <sarah.goslee@gmail.com>:
>
>  You mean like the examples in help("heatmap") ?
>>
>> On Tue, Sep 6, 2011 at 1:20 PM, Jinrui Xu <jinruixu@umich.edu> wrote:
>>
>>> Hi everyone,
>>>
>>> I have three numerica vectors: x, y, z. I want to plot a heatmap or
>>> surface
>>> plot of z against x and y. Is there any package for this? If possible,
>>> please drop me several lines of example code. Thanks!
>>>
>>> jinrui,
>>>
>>>
>> --
>> Sarah Goslee
>> http://www.**functionaldiversity.org <http://www.functionaldiversity.org>
>>
>>
>>
>>
>
>
> --
> Ph.D Student, Bioinformatics Program
> Center for Computational Medicine and Bioinformatics (CCMB)
> The University of Michigan
> 100 Washtenaw Avenue
> Ann Arbor, MI 48109-2218
>
> 1075 Natural Science Building
> 830 North University Avenue
> Ann Arbor, MI 48109-1048
> Tel (lab): 734-763-0514
>
> http://www-personal.umich.edu/**~jinruixu/<http://www-personal.umich.edu/%7Ejinruixu/>
>
>
> ______________________________**________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/**
> posting-guide.html <http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

