Created
July 28, 2012 07:39
-
-
Save informationsea/3192275 to your computer and use it in GitHub Desktop.
Draw Heatmap with R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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