Creation of a stock chart object that can be inserted
in a 'Microsoft' document. When open is omitted the chart is
a High-Low-Close chart. When open is provided it becomes an
Open-High-Low-Close chart with up/down bars (candlestick).
See also
chart_settings(), chart_ax_x(), chart_ax_y(),
chart_theme(), chart_labels()
Other 'Office' chart objects:
ms_areachart(),
ms_barchart(),
ms_boxplotchart(),
ms_bubblechart(),
ms_chart_combine(),
ms_funnelchart(),
ms_histogramchart(),
ms_linechart(),
ms_paretochart(),
ms_piechart(),
ms_radarchart(),
ms_scatterchart(),
ms_sunburstchart(),
ms_treemapchart(),
ms_waterfallchart()
Examples
library(officer)
dat <- data.frame(
date = as.Date("2024-01-01") + 0:4,
open = c(44, 25, 38, 50, 34),
high = c(55, 57, 57, 58, 58),
low = c(11, 12, 13, 11, 25),
close = c(32, 35, 34, 35, 43)
)
# HLC chart
stock_hlc <- ms_stockchart(
data = dat, x = "date",
high = "high", low = "low", close = "close"
)
stock_hlc
#> * 'ms_stockchart' object
#>
#> * original data [15,3] (sample):
#> date .mschart_y .mschart_group
#> 1 2024-01-01 55 high
#> 2 2024-01-02 57 high
#> 3 2024-01-03 57 high
#> 4 2024-01-04 58 high
#> 5 2024-01-05 58 high
#>
#> * series data [5,4] (sample):
#> date high low close
#> 1 2024-01-01 55 11 32
#> 2 2024-01-02 57 12 35
#> 3 2024-01-03 57 13 34
#> 4 2024-01-04 58 11 35
#> 5 2024-01-05 58 25 43
# OHLC chart (candlestick)
stock_ohlc <- ms_stockchart(
data = dat, x = "date",
open = "open", high = "high",
low = "low", close = "close"
)
stock_ohlc
#> * 'ms_stockchart' object
#>
#> * original data [20,3] (sample):
#> date .mschart_y .mschart_group
#> 1 2024-01-01 44 open
#> 2 2024-01-02 25 open
#> 3 2024-01-03 38 open
#> 4 2024-01-04 50 open
#> 5 2024-01-05 34 open
#>
#> * series data [5,5] (sample):
#> date open high low close
#> 1 2024-01-01 44 55 11 32
#> 2 2024-01-02 25 57 12 35
#> 3 2024-01-03 38 57 13 34
#> 4 2024-01-04 50 58 11 35
#> 5 2024-01-05 34 58 25 43
