Created
February 19, 2015 19:04
-
-
Save timelyportfolio/deaf54842e278098e96b to your computer and use it in GitHub Desktop.
R | rbokeh image plots with various plots
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
# 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