This doc shows 2 examples using {rbokeh}.

Subplots (facets)

There are several ways to do this. Official document uses for loop and {htmlwidgets} blog post uses lapply.

The below example uses {dplyr} to achieve the same result.

# use mpg as sample data. Not required by rbokeh itself.
library(ggplot2)
head(mpg)
##   manufacturer model displ year cyl      trans drv cty hwy fl   class
## 1         audi    a4   1.8 1999   4   auto(l5)   f  18  29  p compact
## 2         audi    a4   1.8 1999   4 manual(m5)   f  21  29  p compact
## 3         audi    a4   2.0 2008   4 manual(m6)   f  20  31  p compact
## 4         audi    a4   2.0 2008   4   auto(av)   f  21  30  p compact
## 5         audi    a4   2.8 1999   6   auto(l5)   f  16  26  p compact
## 6         audi    a4   2.8 1999   6 manual(m5)   f  18  26  p compact
library(rbokeh)

mpg %>% dplyr::group_by(class) %>%
 dplyr::do(dummy = ly_points(figure(width = 200, height = 200), 
                             x = displ, y = hwy,
                             data = ., size = 2)) %>%
  { as.list(.[['dummy']]) } %>%
  grid_plot(nrow = 3, ncol = 3, same_axes = TRUE )

Grouped plots

Frequently I need grouped histogram / density plots. Though ly_hist and ly_density seem to have no direct option, we can use Reduce to do this.

# prepare color palette
library(scales)

colors <- scales::hue_pal()(length(levels(mpg$class)))
colors <- setNames(colors, levels(mpg$class))
colors
##    2seater    compact    midsize    minivan     pickup subcompact 
##  "#F8766D"  "#C49A00"  "#53B400"  "#00C094"  "#00B6EB"  "#A58AFF" 
##        suv 
##  "#FB61D7"
ghist <- function(fig, group) {
  ly_hist(fig, x = hwy, data = dplyr::filter(mpg, class == group),
          breaks = seq(10, 45, 5), color = colors[[group]])
}
Reduce(ghist, levels(mpg$class), figure())