Skip to content

Instantly share code, notes, and snippets.

@informationsea
Created July 28, 2012 07:39
Show Gist options
  • Save informationsea/3192275 to your computer and use it in GitHub Desktop.
Save informationsea/3192275 to your computer and use it in GitHub Desktop.
Draw Heatmap with R
library(lattice)
library(gregmisc)
myxyplot <- function(x, y,
xlab=deparse(substitute(x)),
ylab=deparse(substitute(y)),
xlim,
ylim,
nbins=c(50, 50), alpha=0.05, func=function(x){x}, sub="", heat.map=T) {
c <- cor.test(x, y)
main <- sprintf("Correlation: %f p-value: %f", c[[4]], c[[3]])
print(xyplot(y ~ x, xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab, alpha=alpha, pch=20, grid=T, main=main, sub=sub))
if (heat.map) {
h2c <- hist2d(x, y, show=F, same.scale=F, nbins=nbins)
print(image(h2c$x, h2c$y, func(h2c$counts), xlab=xlab, ylab=ylab, main=main, sub=sub))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment