I’ve updated my [metricsgraphics](https://github.com/hrbrmstr/metricsgraphics) package to version [0.7](https://github.com/hrbrmstr/metricsgraphics/releases/tag/v0.7). The core [MetricsGraphics](http://metricsgraphicsjs.org) JavaScript library has been updated to version 2.1.0 (from 1.1.0). Two blog-worthy features since releasing version 0.5 are `mjs_grid` (which is a `grid.arrange`-like equivalent for `metricsgraphics` plots and `mjs_add_rollover` which lets you add your own custom rollover text to the plots.
### The Grid
The `grid.arrange` (and `arrangeGrob`) functions from the `gridExtra` package come in handy when combining `ggplot2` charts. I wanted a similar way to arrange independent or linked `metricsgraphics` charts, hence `mjs_grid` was born.
`mjs_grid` uses the tag functions in `htmltools` to arrange `metricsgraphics` plot objects into an HTML `
` structure. At present, only uniform tables are supported, but I’m working on making the grid feature more flexible (just like `grid.arrange`). The current functionality is pretty straightforward:
– You build individual `metricsgraphics` plots;
– Optionally combine them in a `list`;
– Pass in the plots/lists into `mjs_grid`;
– Tell `mjs_grid` how many rows & columns are in the grid; and
– Specify the column widths
But, code > words, so here are some examples. To avoid code repetition, note that you’ll need the following packages available to run most of the snippets below:
Since your can pass a `list` as a parameter, you can generate many (similar) plots and then grid-display them without too much code. This one generates 7 random histograms with linked rollovers and displays them in grid. Note that this example has `mjs_grid` using the same algorithm `grid.arrange` does for auto-computing “optimal” grid size.
And, you can use `do` from `dplyr` to get `ggplot2` `facet_`-like behavior (though, one could argue that interactive graphics should use controls/selectors vs facets). This example uses the `tips` dataset from `reshape2` and creates a list of plots that are then passed to `mjs_grid`:
I’ve had a few requests to support the use of different rollovers and this is a first stab at exposing MetricsGraphics’ native functionality to users of the `metricsgraphics` package. The API changed from MG 1.1.0 to 2.2.0, so I’m _kinda_ glad I waited for this. It requires knowledge of javascript, D3 and the use of `{{ID}}` as part of the CSS node selector when targeting the MetricsGraphics SVG element that displays the rollover text. Here is a crude, but illustrative example of how to take advantage of this feature (mouseover the graphics to see the altered text):
If you are using `metricsgraphics`, drop a link in the comments here to show others how you’re using it! If you need/want some functionality (I’m hoping to get `xts` support into the 0.8 release) that isn’t already in existing feature requests or something’s broken for you, post a new [issue on github](https://github.com/hrbrmstr/metricsgraphics/issues).
By Security-Vision » New release (0.7) of metricsgraphics htmlwidget — grids & rollovers on 01 Feb 2015 at 11:07 am
[…] which lets you add your own custom rollover text to the plots. The Grid The […], Security Bloggers Network, hrbrmstr, […]
By New release (0.7) of metricsgraphics htmlwidget — grids & rollovers | infopunk.org on 01 Feb 2015 at 2:20 pm
[…] I’ve updated my metricsgraphics package to version 0.7. The core MetricsGraphics JavaScript library has been updated to version 2.1.0 (from 1.1.0). Two blog-worthy features since releasing version 0.5 are mjsgrid (which is a grid.arrange-like equivalent for metricsgraphics plots and mjsadd_rollover which lets you add your own custom rollover text to the plots. The Grid The […] […]
2 Trackbacks/Pingbacks
[…] which lets you add your own custom rollover text to the plots. The Grid The […], Security Bloggers Network, hrbrmstr, […]
[…] I’ve updated my metricsgraphics package to version 0.7. The core MetricsGraphics JavaScript library has been updated to version 2.1.0 (from 1.1.0). Two blog-worthy features since releasing version 0.5 are mjsgrid (which is a grid.arrange-like equivalent for metricsgraphics plots and mjsadd_rollover which lets you add your own custom rollover text to the plots. The Grid The […] […]