strwidth plot.new中的错误尚未被调用

时间:2018-02-21 18:58:28

标签: r

bassModel <- function(p, q, N, T = 100) {
  S = double(T)
  Y = double(T + 1)
  Y[1] = 0
  for(t in 1:T) {
    S[t] = p * N + (q - p) * Y[t] - (q / N) * (Y[t] ** 2)
    Y[t + 1] = Y[t] + S[t]
  }
  return(list(sales = S,cumSales = cumsum(S)))
}
Spred <- bassModel(p, q, N)$sales
Spred <- ts(Spred, start = c(2007, 3), freq =4)
Sales <- ts(sales, start = c(2007, 3), freq =4)
ts.plot(Sales, Spred, col = c("blue", "red"))
legend("topleft", c("actual", "Bass Model"), fill = c("blue", "red"))
title(paste("Predicted Sales","(p = ",format(p,digits=4),") ","(q =                 ",format(q,digits=4),") ","(N = ",format(N,digits=0),")"))

当我执行代码时。我收到了错误信息。

strwidth错误(图例,单位=“用户”,cex = cex,font = text.font):plot.new尚未调用

请分享任何想法来解决它。

0 个答案:

没有答案