设置 quantmod::chart_Series 的背景颜色
Set the background color for quantmod::chart_Series
我有一个名为 adjPrices.xts
的 xts
对象,其中包含 OHLC 股票价格历史记录。函数 quantmod::chartSeries,当如下调用时,将此数据绘制在黑色背景的图表中:
chartSeries(adjPrices.xts,
subset = '2014-07-01::2015-07-01',
type = 'bars',
name = paste(symbol, 'Adjusted Prices'),
TA = NULL)
但是,quantmod::chart_Series 使用相同的选项创建一个白色背景的图表:
chart_Series(adjPrices.xts,
subset = '2014-07-01::2015-07-01',
type = 'bars',
name = paste(symbol, 'Adjusted Prices'),
TA = NULL)
我想将第二个绘图的背景颜色更改为黑色,我正在按照 this answer 中建议的方法进行操作。 chart_theme()的颜色属性为
> chart_theme()$col
$`bg`
[1] "#FFFFFF"
$label.bg
[1] "#F0F0F0"
$grid
[1] "#F0F0F0"
$grid2
[1] "#F5F5F5"
$ticks
[1] "#999999"
$labels
[1] "#333333"
$line.col
[1] "darkorange"
$dn.col
[1] "red"
$up.col
[1] NA
$dn.border
[1] "#333333"
$up.border
[1] "#333333"
这向我建议我可以将背景颜色设置为黑色,如下所示:
myTheme <- chart_theme()
myTheme$col$`bg` <- "black"
chart_Series(adjPrices.xts,
subset = '2014-07-01::2015-07-01',
theme = myTheme,
type = 'bars',
name = paste(symbol, 'Adjusted Prices'),
TA = NULL)
但是生成的图表仍然是白色背景:
我还尝试按如下方式定义 myTheme
:
myTheme <- chart_theme()
myTheme$col$`bg` <- "#000000"
但生成的图表仍然有白色背景。
如何在使用 chart_Series() 时设置黑色背景?
目前你不能。在 github 上有一个尚未解决的旧问题 issue #25。解决方法是使用 par
:
调用 R 图形参数
这将创建一个黑色背景。
par_old <- par(bg = "black")
chart_Series(SPY)
par(par_old)
其他一些解决方法是使用 rtsplot。基于 R 基础图形,可以选择绘制蜡烛图。背景颜色通过 par
:
设置
rtsplot::rtsplot(SPY, type = "candle")
xts 有一个绘图环境 plot.xts,但它不处理蜡烛图。
Tidyquant 有 geom_candlestick
用于 ggplot2,但如果您使用 ggplot2 > 3.0,这些目前会失败。看到这个 tidyquant github issue
我有一个名为 adjPrices.xts
的 xts
对象,其中包含 OHLC 股票价格历史记录。函数 quantmod::chartSeries,当如下调用时,将此数据绘制在黑色背景的图表中:
chartSeries(adjPrices.xts,
subset = '2014-07-01::2015-07-01',
type = 'bars',
name = paste(symbol, 'Adjusted Prices'),
TA = NULL)
但是,quantmod::chart_Series 使用相同的选项创建一个白色背景的图表:
chart_Series(adjPrices.xts,
subset = '2014-07-01::2015-07-01',
type = 'bars',
name = paste(symbol, 'Adjusted Prices'),
TA = NULL)
我想将第二个绘图的背景颜色更改为黑色,我正在按照 this answer 中建议的方法进行操作。 chart_theme()的颜色属性为
> chart_theme()$col
$`bg`
[1] "#FFFFFF"
$label.bg
[1] "#F0F0F0"
$grid
[1] "#F0F0F0"
$grid2
[1] "#F5F5F5"
$ticks
[1] "#999999"
$labels
[1] "#333333"
$line.col
[1] "darkorange"
$dn.col
[1] "red"
$up.col
[1] NA
$dn.border
[1] "#333333"
$up.border
[1] "#333333"
这向我建议我可以将背景颜色设置为黑色,如下所示:
myTheme <- chart_theme()
myTheme$col$`bg` <- "black"
chart_Series(adjPrices.xts,
subset = '2014-07-01::2015-07-01',
theme = myTheme,
type = 'bars',
name = paste(symbol, 'Adjusted Prices'),
TA = NULL)
但是生成的图表仍然是白色背景:
myTheme
:
myTheme <- chart_theme()
myTheme$col$`bg` <- "#000000"
但生成的图表仍然有白色背景。
如何在使用 chart_Series() 时设置黑色背景?
目前你不能。在 github 上有一个尚未解决的旧问题 issue #25。解决方法是使用 par
:
这将创建一个黑色背景。
par_old <- par(bg = "black")
chart_Series(SPY)
par(par_old)
其他一些解决方法是使用 rtsplot。基于 R 基础图形,可以选择绘制蜡烛图。背景颜色通过 par
:
rtsplot::rtsplot(SPY, type = "candle")
xts 有一个绘图环境 plot.xts,但它不处理蜡烛图。
Tidyquant 有 geom_candlestick
用于 ggplot2,但如果您使用 ggplot2 > 3.0,这些目前会失败。看到这个 tidyquant github issue