-
-
Save ds-jim/e44a709a842573dbae5ca2e887a2fecd to your computer and use it in GitHub Desktop.
Smoothed heatmap without chunkiness of stat_bin2d
This file contains 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(ggplot2) | |
df <- data.frame(x=rnorm(1000), y=rnorm(1000)) | |
jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000")) | |
ggplot(df[sample(1:nrow(df), 1000), ], aes(x, y)) + | |
stat_density2d(geom="tile", aes(fill=..density.., alpha=sqrt(sqrt(..density..))), contour=FALSE, n=100) + | |
scale_alpha(range = c(0.5, 1.0)) + scale_fill_gradientn(colours = jet.colors(10), trans="sqrt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment