fig_candle: Candle

Description Usage Arguments Details Examples

View source: R/figures.R

Description

Add a candle figure to the chart.

Usage

1
2
3
4
5
6
7
8
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:

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()

devOpifex/g2r documentation built on Jan. 16, 2022, 12:36 a.m.