R/bar.r

Defines functions mjs_bar

Documented in mjs_bar

#' metricsgraphics.js bar chart "geom"
#'
#' This function adds a bar "geom" to a metricsgraphics.js html widget.
#'
#' @param mjs metricsgraphics plot object
#' @param bar_height width of bars
#' @param binned is data already binned? (default: \code{TRUE} - yes)
#' @return metricsgraphics object
#' @note metricsgraphics.js currently has "meh" support for bar charts
#' @export
#' @examples
#' data.frame(year=seq(1790, 1970, 10),
#'            uspop=as.numeric(uspop)) %>%
#'   mjs_plot(x=year, y=uspop, width=300, height=400) %>%
#'   mjs_bar()
#'
mjs_bar <- function(mjs,
                    bar_height=20, binned=TRUE) {
  mjs$x$data[, mjs$x$y_accessor] <- as.character(mjs$x$data[, mjs$x$y_accessor])
  mjs$x$chart_type <- "bar"
  mjs$x$bar_height <- bar_height
  mjs$x$binned <- binned
  mjs$x$geom <- "bar"
  mjs
}

Try the metricsgraphics package in your browser

Any scripts or data that you put into this service are public.

metricsgraphics documentation built on May 29, 2017, 10:58 a.m.