Site icon R-bloggers

rbokeh Version 0.5.0 Released

[This article was first published on Ryan Hafen, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The rbokeh package version 0.5.0 was recently released. For those not familiar with rbokeh, it is a plotting library based on BokehJS with the goal of making it easy to flexibly create declarative interactive web-based visualizations in R. To get an overview of what you can do with it, please see here.

< !--more-->

At the heart of this update is a significant amount of internal retooling to be compatible with the latest BokehJS library and to be more robust in general. There are many improvements to BokehJS which are inherited by supporting it.

You can install the new update with:

install.packages("rbokeh")

A full list of updates is provided at the end of this post. Many of these are too small to warrant extended coverage, but as a whole comprise a significant update. Here are a few examples showing some of the updated functionality.

Maps with Google API Key

Google has somewhat recently required tools that use Google Maps to have a Google Maps API key. Earlier versions of rbokeh don’t support this as it wasn’t supported in BokehJS until the current version.

You can get your own API key here. Once you have a key, you can either set it as an environment variable, GMAP_API_KEY, set it as an option in your R session with options(GMAP_API_KEY=xxx), or provide it explicitly to gmap().

gmap(width = 700, height = 400,
  zoom = 4, lat = 37.5, lng = -96.4,
  map_style = gmap_style("blue_water")) %>%
  ly_points(long, lat, hover = list(name, pop), data = maps::us.cities)

Since the environment this document is being generated from has a Google Maps API key environment variable, the map plot works.

Note that there is an intermittent issue I’ve noticed recently with embedding Google Maps in iframes in Chrome where the plot may show up gray if it was not in view while the page was loaded. If you can’t see the plot above, try refreshing your page. I’m trying to get to the bottom of this but it shouldn’t generally be an issue because using iframes to embed rbokeh plots into web pages isn’t a common use case that I’m aware of.

Bar charts with hover

ly_bar now has a hover argument that will show the size of the bar on hover. Also, bar charts and boxplots can now be plotted on either axis by simply specifying which axes the variables belong to.

figure() %>%
  ly_bar(variety, yield, color = year,
    data = lattice::barley, hover = TRUE) %>%
  theme_axis("x", major_label_orientation = 90)

Updates like this that concern high-level layer functions are usually quite straightforward so if there are any requests for features to add to existing layer functions or new layer functions are desired, please file an issue or better yet, contribute a fix.

Themes

Several improvements were made to themes. While most of these were minor, one bigger update is the ability to apply a theme across a grid plot (instead of theming each plot independently). For example:

idx <- split(1:150, iris$Species)
figs <- lapply(idx, function(x) {
  figure(width = 230, height = 300) %>%
    ly_points(Sepal.Length, Sepal.Width, data = iris[x, ],
      hover = list(Sepal.Length, Sepal.Width))
})
grid_plot(figs, same_axes = TRUE) %>%
  set_theme(bk_ggplot_theme)

What’s next

There are several things I’d like to do with this package. To give an idea of what will hopefully be coming up next:

Thanks

Many thanks to all the users for your input, issues, and patience. This is still an early growing project but I’m excited about the direction it is going.

If any users feel like there are issues or requests that are not getting the attention they need, please hop on Github and let me know.

Full list of updates in 0.5.0

To leave a comment for the author, please follow the link and comment on their blog: Ryan Hafen.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.