Add a candle figure to the chart.

fig_candle(
  g,
  ...,
  sync = TRUE,
  data = NULL,
  inherit_asp = TRUE,
  alias = "range"
)

Arguments

g

An object of class g2r or g2Proxy as returned by g2() or g2_proxy().

...

Options to pass to the figure, including asp(), and adjust(), active(), selected(), and config(), other key value pairs of are passed to style.

sync

Whether to sync the axis data (align) with that used in other figures, set to FALSE to not sync or set to a character string to use as name of sync group.

data

A dataset (data.frame or tibble) to use to draw the figure.

inherit_asp

Whether to inherit the aspects paseed to g2() initialisation function.

alias

Name of the range to display on tooltips, labels, etc.

Details

Requires the following aspects defined:

  • open

  • close

  • high

  • low

If no color argument is passed the candles are colored according to their trend (open > close = "up").

Examples

stock <- structure(
  list(
    date = structure(c(18626, 18627, 18631, 18632), class = "Date"),
    open = c(39.52, 39.330002, 40.169998, 41.5),
    high = c(
      39.73,
      40,
      41.560001,
      42.040001
    ),
    low = c(
      39.200001,
      39.029999,
      39.939999,
      40.77
    ),
    close = c(
      39.34,
      39.880001,
      41.400002,
      41.16
    )
  ),
  row.names = c(NA, -4L),
  class = c(
    "tbl_df",
    "tbl",
    "data.frame"
  )
)

g2(stock, asp(date, open = open, close = close, high = high, low = low)) %>%
  fig_candle() %>%
  gauge_x_time_cat()