我正在使用xts
软件包。
library(xts)
以下完全可以正常工作:
mydata = xts(rnorm(200), order.by = Sys.Date() - 1:200)
layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE),
widths=c(1,1), heights=c(1,2))
plot(mydata, main = 'mydata Time Series')
acf(mydata, main = 'mydata acf', lag = 10)
pacf(mydata, main = 'mydata pacf', lag = 10)
但是当我使用完全相同的东西作为函数时,图显示得不好
mydata = xts(rnorm(200), order.by = Sys.Date() - 1:200)
return_plot <- function(mydata, lag = 10){
layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE),
widths=c(1,1), heights=c(1,2))
plot(mydata, main = 'mydata Time Series')
acf(mydata, main = 'mydata acf', lag = lag )
pacf(mydata, main = 'mydata pacf', lag = lag)
}
return_plot(mydata)
知道为什么会这样吗?
答案 0 :(得分:4)
在函数中使用print(plot(mydata, main = 'mydata Time Series'))
。