mjs_add_line: Add a new line to a metricsgraphics.js linechart "geom"

Description Usage Arguments Value Note Examples

Description

This function adds a line to an existing mjs_line "geom". Specify the bare or quoted name of the column to use in y_accessor and it will be added to the plot.

Usage

1
mjs_add_line(mjs, y_accessor, color = NULL)

Arguments

mjs

metricsgraphics plot object

y_accessor

bare or quoted name of column to add to the existing line plot

color

line color. Use NULL (the default) to use default Metrics Graphics colors or if you plan on using CSS to control the colors.

Value

metricsgraphics object

Note

You must have called mjs_line first before adding additional columns. If you plan on using cusom colors, all lines must have a color value or the result is non-deterministic.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
set.seed(1492)
stocks <- data.frame(
  time = as.Date('2009-01-01') + 0:9,
  X = rnorm(10, 0, 1),
  Y = rnorm(10, 0, 2),
  Z = rnorm(10, 0, 4))

stocks %>%
  mjs_plot(x=time, y=X) %>%
  mjs_line() %>%
  mjs_add_line(Y) %>%
  mjs_add_line(Z) %>%
  mjs_axis_x(xax_format="date")

metricsgraphics documentation built on May 1, 2019, 8:07 p.m.