简体   繁体   English

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

[英]Plotting legend and getting: Error in strwidth(legend, units = “user”, cex = cex, font = text.font) : plot.new has not been called yet

I've created multiple time series in rStudio. 我在rStudio中创建了多个时间序列。 And I am attempting to plot it using ts.plot() . 我试图用ts.plot()绘制它。 The plot works fine but adding a legend causes issues and gives : 情节工作正常,但添加图例会导致问题并给出:

Error in strwidth(legend, units = "user", cex = cex, font = text.font) : plot.new has not been called yet. strwidth错误(图例,单位=“用户”,cex = cex,font = text.font):plot.new尚未调用。

I have tried running all the code at once and adjusting the parameters. 我尝试一次运行所有代码并调整参数。

ts.plot(nltnr.ts, peitnr.ts, nstnr.ts, nbtnr.ts, qbtnr.ts, ontnr.ts, mbtnr.ts, sktnr.ts, abtnr.ts, bctnr.ts, yktnr.ts, nttnr.ts, nvtnr.ts,
        gpars = list(
        ylab = "Amount in millions",
        col=1:12,
        legend("bottom", legend = 1:12)
        ))

ts.plot(nltnr.ts, peitnr.ts, nstnr.ts, nbtnr.ts, qbtnr.ts, ontnr.ts, mbtnr.ts, sktnr.ts, abtnr.ts, bctnr.ts, yktnr.ts, nttnr.ts, nvtnr.ts,
        gpars = list(
        ylab = "Amount in millions",
        col=1:12))
        legend("bottom", legend = 1:12)

Try running the legend() command after doing your plot, and not while running your plot. 在绘制绘图后尝试运行legend()命令,而不是在运行绘图时运行。

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

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