Update to metricsgraphics 0.9.0 (now on CRAN)

It’s been a while since I’ve updated my metricsgraphics package. The hit list for changes includes:

  • Fixes for the new ggplot2 release (metricsgraphics uses the movies data set which is now in ggplot2movies)
  • Updated all javascript libraries to the most recent versions
  • Borrowed the ability to add CSS rules to a widget from taucharts (mjs_add_css_rule)
  • Added a metricsgraphics plugin to enable line chart region annotation (mjs_annotate_region)
  • Enabled explicit coloring line/area charts (it was a new feature in the underlying Metrics-Graphics library)
  • You can use bare or quoted names when specifying the x & y accessors and can also use a variable name
  • You can now use the metricsgraphics title & description capabilities, but doing so voids any predictable/specified widget height/width and the description functionality is really only suited for bootstrap templates

I think all that can be demonstrated in the following snippet:

dat <- read.csv("http://real-chart.finance.yahoo.com/table.csv?s=AAPL&a=07&b=9&c=1996&d=11&e=21&f=2015&g=d&ignore=.csv",
DATE <- "Date"
dat %>%
  filter(Date>="2008-01-01") %>% 
  mjs_plot(DATE, y="Low", title="AAPL Stock (2008-Present)", width=800, height=500) %>% 
  mjs_line(color="#6a3d9a") %>% 
  mjs_add_line(High, color="#ff7f00") %>% 
  mjs_axis_x(xax_format="date") %>% 
  mjs_add_css_rule("{{ID}} .blk { fill:black }") %>%
  mjs_annotate_region("2013-01-01", "2013-12-31", "Volatility", "blk") %>% 
  mjs_add_marker("2014-06-09", "Split") %>% 
  mjs_add_marker("2012-09-12", "iPhone 5") %>% 
  mjs_add_legend(c("Low", "High"))

NOTE: I’m still trying to figure out why WebKit on Safari renders the em dashes and Chrome does not.

Buy on AmazonDDS Blog
DDS PodcastAmazon Author Page

7 Comments Update to metricsgraphics 0.9.0 (now on CRAN)

  1. Barry

    Hello, I’m puzzled by one element of this syntax: what does ‘%>%’ mean? I’ve searched and can’t find it (likely because it’s confounded with control symbols).


  2. Pingback: Update to metricsgraphics 0.9.0 (now on CRAN) | Mubashir Qasim

    1. hrbrmstr

      I can see special characters being hard to search for. The “piping” phenom has been a “thing” for about 18 months now on all the various r-bloggers blogs and twitters. Plus it’s in the dplyr (et al) help & vignettes. You do raise a gd point, though, and I’ll definitely make sure I note things like “%>%” usage in the future. Interestingly enough, I don’t really do much with pipes in the packages I write since it’s harder to pinpoint errors when things break.

  3. David

    It would be great if announcements of new package releases such as this began with a summary of what the package does… most do not, so this is the first stop on my campaign for more informative release notes. Thanks!


Leave a Reply