希望大神指教:换了一台电脑就运行不了的R代码(报错: plot.new has not been called yet)

今天遇到了一个很奇怪的代码,在别的电脑上能运行,结果在自己的电脑上,却一直报错。主要问题就是legend添加图例部分,我的电脑上运行那一行代码,要么运行成功,但是不显示图例,要么运行不成功,并提示我:Error in (function (s, units = “user”, cex = NULL, font = NULL, vfont = NULL, : plot.new has not been called yet

如果有大神知道是什么原因,可以给我指点一下!!!
代码:

library(rio)
library(plyr)
library(ggplot2)
library(ggpmisc)
library(tidyverse)

setwd("D:/File")
df<-import("data.xlsx")
Model1 <- list(formula = y ~ 1.3+a*x^b,start=list(a=2,b=4))
Model2 <- list(formula = y ~ 1.3+a*x*(1+x)^-b,start=list(a=2,b=2))
Model3 <- list(formula = y ~ 1.3+a*exp(-b*x^-1),start=list(a=6,b=4))

ggplot(df,aes(x=D,y=H))+ 
  geom_point(size=1,colour="grey30")+
  theme_bw()+
  theme(panel.grid = element_blank())+
  labs(x="胸径(cm)",
       y="树高(m)")+
  stat_fit_augment(method = "nls",method.args = Model1,color="green")+
  stat_fit_augment(method = "nls",method.args = Model2,color="red")+
  stat_fit_augment(method = "nls",method.args = Model3,color="purple")
legend(x = 50, y = 13,
       title="拟合曲线",
       fill = c("green","red","purple"),
       legend = c("Model1", "Model2","Model3"),
       cex = 0.75)

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jackson的生态模型

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值