Skip to content

Instantly share code, notes, and snippets.

@timelyportfolio
Created February 19, 2015 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timelyportfolio/deaf54842e278098e96b to your computer and use it in GitHub Desktop.
Save timelyportfolio/deaf54842e278098e96b to your computer and use it in GitHub Desktop.
R | rbokeh image plots with various plots
# from ?densCols
x1 <- matrix(rnorm(1e3), ncol = 2)
x2 <- matrix(rnorm(1e3, mean = 3, sd = 1.5), ncol = 2)
x <- rbind(x1, x2)
# try to replicate this marvelous little thing in rbokeh
# ashame this thing doesn't get nearly enough attention
smoothScatter(x)
library(rbokeh)
library(pipeR)
# smoothScatter uses this function
# we should be able to use it also
grDevices:::.smoothScatterCalcDensity(x,nbin=128) %>>%
(ss~
ly_image(
figure( width = 700, height = 400, xlim = range(ss$x1), ylim = range(ss$x2) )
,ss$fhat
,x = min(ss$x1)
,y = min(ss$x2)
,dw = max(ss$x1) - min(ss$x1)
,dh = max(ss$x2) - min(ss$x2)
,palette = "Spectral4"
)
)
# another one from http://www.cyclismo.org/tutorial/R/intermediatePlotting.html
numberWhite <- rhyper(30,4,5,3)
numberChipped <- rhyper(30,2,7,3)
smoothScatter(numberWhite,numberChipped,
xlab="White Marbles",ylab="Chipped Marbles",main="Drawing Marbles")
grDevices:::.smoothScatterCalcDensity(cbind(numberWhite,numberChipped),nbin=128) %>>%
(ss~
ly_image(
figure( width = 700, height = 400, xlim = range(ss$x1), ylim = range(ss$x2) )
,ss$fhat
,x = min(ss$x1)
,y = min(ss$x2)
,dw = max(ss$x1) - min(ss$x1)
,dh = max(ss$x2) - min(ss$x2)
,palette = "BuPu9"
)
)
grDevices:::.smoothScatterCalcDensity(cbind(numberWhite,numberChipped),nbin=128) %>>%
(ss~
ly_image(
figure( width = 700, height = 400, xlim = range(ss$x1), ylim = range(ss$x2) )
,ss$fhat
,x = min(ss$x1)
,y = min(ss$x2)
,dw = max(ss$x1) - min(ss$x1)
,dh = max(ss$x2) - min(ss$x2)
,palette = c("#FFFFFF",RColorBrewer::brewer.pal(9,"Blues"))
)
)
grDevices:::.smoothScatterCalcDensity(cbind(numberWhite,numberChipped),nbin=128) %>>%
(ss~
ly_image(
figure( width = 700, height = 400, xlim = range(ss$x1), ylim = range(ss$x2) )
,ss$fhat
,x = min(ss$x1)
,y = min(ss$x2)
,dw = max(ss$x1) - min(ss$x1)
,dh = max(ss$x2) - min(ss$x2)
,palette = c("#FFFFFF",RColorBrewer::brewer.pal(9,"Greys"))
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment