Skip to content

Instantly share code, notes, and snippets.

View ds-jim's full-sized avatar

James ds-jim

View GitHub Profile
@ds-jim
ds-jim / new_gist_file.r
Created June 6, 2018 15:45 — forked from 04pallav/new_gist_file.r
Force ggplot to stop scientific notation
options("scipen"=-100, "digits"=4)
@ds-jim
ds-jim / R - smooth density heatmap
Created June 6, 2018 10:45 — forked from kalebr/R - smooth density heatmap
Smoothed heatmap without chunkiness of stat_bin2d
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")