Week07 - bokeh now for R
February 17, 2015
htmlwidgets News This Week
-@hrbrmstr - d3 streamgraph layout streamgraph
. Bob Rudis builds on his list of authored widgets with this very nice htmlwidget
for streamgraphs. See the announcement for a through discussion.
-@smartinsightsfromdata - rpivotTable
provides a htmlwidget
for the very well done PivotTable.js by Nicholas Krutchen. Not only will Excel users feel more at home now, but also there are lots of very interesting views, such as treemaps and heatmaps. If you still like old-fashioned tables
and their derivatives in R like I do, please let me know, and maybe we can convince the author to add the couple lines to support these very handy and far-from-obsolete beauties.
This Week’s Widget - rbokeh
| bokeh for R
Python and even Scala and Julia have Bokeh
, so R should too. Fortunately, Ryan Hafen from Purdue and Tessara has been applying his very thorough R skills to make rbokeh
, a professionally built htmlwidget
for Bokeh
. Just look at that site and the documentation, and I think you’ll quickly get as excited as I am for the potential of rbokeh
.
I should note that Ryan deserves all the credit for rbokeh
. I simply chipped in with some additional examples, testing, lots of questions, and minor pull requests. I hope I can also help implement a bar chart and full seamless shiny integration. Feel free to contribute any way you can. Every little bit helps.
Examples
I understand how hard it is to motivate R users spoiled by ggplot2
, lattice
, and even base graphics
. Borrowing from these great libraries, Ryan has integrated many good bits into rbokeh
. Enough writing, let’s see some examples. You’ll notice rbokeh
loves modern R pipes.
# devtools::install("hafen/rbokeh")
library(rbokeh)
# basic pipes built in but I love pipeR
library(pipeR)
# diamonds is always my goto for kind of big data
data(diamonds, package="ggplot2")
figure( width = 600, height = 600, title = "Diamonds from ggplot2" ) %>>%
ly_hexbin(
carat
,log(price)
,data = diamonds
)
Bokeh
renders to canvas, so it can handle lots of points.
figure( width = 600, height = 400, title = "Diamonds from ggplot2" ) %>>%
ly_points(
x = carat
, y = price
, data = diamonds
, color = color
, size = 2
)
lm
plugs right into rbokeh
.
figure( width = 700, height = 400, title = "Diamonds lm with rbokeh" ) %>>%
ly_points(
x = carat
, y = price
, data = diamonds
, color = color
, size = 2
) %>>%
ly_abline(
lm( price ~ carat, diamonds )
,type = 2
,width = 3
)
Now would be a great time to show facets
with rbokeh
. grid_plot
gives us a way to achieve these, but facets
require a little extra effort. But hey, we all need to know *apply
anyways. Let’s split the plot above by clarity.
lapply(
levels(diamonds$clarity)
,function(clar){
figure( width = 300, height = 300, title = paste0("Clarity: ",clar )) %>>%
ly_points(
x = carat
, y = price
, data = subset(diamonds,clarity==clar)
, color = color
, size = 2
) %>>%
ly_abline(
lm( price ~ carat, subset(diamonds,clarity==clar) )
,type = 2
,width = 3
)
}
) %>>%
( grid_plot( ., nrow = 2, ncol = 4, same_axes = T ) )
I hope this along with Ryan’s site and documentation will be enough for you to get excited and get started. It is an amazing package with immense functionality. Just look at this periodic table and this baseball hexbin.
Examples from ggplot2
& lattice
books
rbokeh
can do so much that I could write an entire book. I have started by replicating many of the examples from ggplot2
and lattice
books in this Gist.
Thanks
Thanks so much for all the work by
- Ryan Hafen for
rbokeh
- team at Continuum Analytics
- Ramnath Vaidyanathan and RStudio for
htmlwidgets