In their words:
Bokeh is a visualization library that provides a flexible and powerful declarative framework for creating web-based plots. Bokeh renders plots using HTML canvas and provides many mechanisms for interactivity. Bokeh has interfaces in Python, Scala, Julia, and now R.
rbokeh is one of my new favourite R things.
I never used bokeh before, but I am a big fan of the R version.
rbokeh is now my favourite way of quickly visualizing data while doing first pass or exploratory analyses.
When I think “I wonder what this data looks like?”, I jump to
The syntax is efficient and intuitive (maybe because I am already familiar with
ggplot) and I feel I get a lot of great stuff for little effort.
Want the ability to see values when you hover over points? Just add
hover = list(var1, var2).
Want to be able to lasso a group of points on a plot and focus on those? Just add
rbokeh creates plots using HTML canvas, it’s well-suited to plotting in R Markdown documents and embedding plots in web pages like this one.
The following is a summary or repetition of what I learned from the
rbokeh documentation and this post by Bob Rudis.
Why the repetition? In the spirit of “two is one and one is none”, and because it never hurts to have redundancy for knowledge on the internet.
To plot in R / RStudio
You need to install and load the
The documentation is a good introduction to the basic plots you can create. Here is a starter example:
The amount of plot and functionality I get per keystroke still gives me a rush.
That was a basic plot. Let’s do some customization.
To save the plot to an html file
You will need the
From that, you can use the
To embed plot in Jekyll or other web pages
The best way I’ve found is to use an
You can control the plot dimensions from the
robokeh end if you need to:
There is one downside to embedding
rbokeh plots in web pages: they are expensive when it comes to bandwidth.
The two plots on this page are 1.3 MB each.
That’s a lot.
This page is 2.62 MB in total. The
rbokeh plots make up 99% of that.
So you can’t throw these plots around willy-nilly.
Use few and make them count.
Actually, let me be that guy for a second: “use few and make them count” is good advice for plots of any kind.