简体   繁体   English

问:quantmod :: chart_Series和主题不起作用

[英]Q: quantmod::chart_Series and theme not working

I'm trying to change the size of the title by changing the theme 我正在尝试通过更改主题来更改标题的大小

Code: tested on R (3.6.0) 代码:在R(3.6.0)上进行了测试

# R --silent --vanilla < c.r
suppressWarnings(suppressMessages(library(quantmod)))
library(ggplot2)
options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)

getSymbols("IBM", source = "yahoo")
getSymbols("GE", source = "yahoo")

# modify theme
mytheme <- theme(plot.title = element_text(size=8))

# create a PDF
pdf(file = "out.pdf")
par(mfrow = c( 4, 2 ) )
chart_Series(IBM, name="IBM", theme=mytheme)
chart_Series(GE, name="General Electric", theme=mytheme)
dev.off()

Error 错误

Error in if (theme$lylab) { : argument is of length zero
Calls: chart_Series
Execution halted

Super confusing, but chart_Series does not support ggplot2::theme(), you have to modify chart_pars() which isn't well documented. 超级令人困惑,但是chart_Series不支持ggplot2 :: theme(),您必须修改chart_pars(),但文档记录不充分。

This code also unfortunately changes the y-label and x-label sizes as well. 不幸的是,该代码还更改了y标签和x标签的大小。

Code: tested on R (3.6.0) 代码:在R(3.6.0)上进行了测试

# R --silent --vanilla < c.r
suppressWarnings(suppressMessages(library(quantmod)))
options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)

getSymbols("IBM", source = "yahoo")
getSymbols("GE", source = "yahoo")

# modify theme
lilpars <- chart_pars()
lilpars$cex=0.4
bigpars <- chart_pars()
bigpars$cex=1.0


# mytheme <- chart_theme()

# create a PDF
pdf(file = "out.pdf")
par(mfrow = c( 4, 2 ) )
chart_Series(IBM, name="IBM: IBM", pars=bigpars)
chart_Series(GE, name="GE: General Electric", pars=lilpars)
dev.off()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM