[This article was first published on rud.is » R, 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.
Mozilla released the MetricsGraphics.js library back in November of 2014 (gh repo) and was greeted with great fanfare. It’s primary focus is on crisp, clean layouts for interactive time-series data, but they have support for other chart types as well (though said support is far from comprehensive).
One of the package goals (which should be evident from the example) is that it had to conform to the new “piping” idiom, made popular through the magrittr, ggvis and dplyr packages. This made it possible to avoid one function with a ton of parameters and help break out the chart building into logical steps. While it may not have the flexibility of ggplot2, you can do some neat things with MetricsGraphics charts, like use multiple lines:
The htmlwidgets developers go into great detail on how to create a widget, but there are some central points I’ll cover and potentially reiterate.
Third, if you need to customize the html generation function in the main packagename_html file, ensure you pass in class to the main div element. I was very pleased to discover that you can return a list of HTML elements vs a single one:
and that may eventually enable support for facet-like functionality without manually creating multiple plots.
Fourth, try to build around the piping idiom. It makes it so much easier to add parameters and manage the data environment.
Fifth, use iframes for embedding your visualizations in other documents (like this blog post). It avoids potential namespace collisions and frees you from having to cut/paste HTML from one doc to another.
Currently, metricsgraphics is at 0.4.1 and has support for most of the basic chart types along with linking charts (in Rmd files). You can install it from the github repo and make sure to file all issues or feature requests there. If you make something with it like @abreslerdid, drop a note in the comments!
Now, go forth and wrap some libraries!
To leave a comment for the author, please follow the link and comment on their blog: rud.is » R.