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

时间:2019-06-16 00:03:18

标签: r quantmod

我正在尝试通过更改主题来更改标题的大小

代码:已在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 in if (theme$lylab) { : argument is of length zero
Calls: chart_Series
Execution halted

1 个答案:

答案 0 :(得分:0)

超级混乱,但是chart_Series不支持ggplot2 :: theme(),您必须修改没有充分说明的chart_pars()。

不幸的是,此代码还更改了y标签和x标签的大小。

代码:已在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()