Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:在一个循环中绘制多个时间序列。xy.coords中的错误(x,y,xlabel,ylabel,log):';x';和';y';长度不同_R_Loops_Plot_Time Series - Fatal编程技术网

R:在一个循环中绘制多个时间序列。xy.coords中的错误(x,y,xlabel,ylabel,log):';x';和';y';长度不同

R:在一个循环中绘制多个时间序列。xy.coords中的错误(x,y,xlabel,ylabel,log):';x';和';y';长度不同,r,loops,plot,time-series,R,Loops,Plot,Time Series,我试图从一个包含134列的数据库中绘制出许多时间序列,每列一个ts,然后将其保存在一个.jpg文件中。我正在使用一个循环。我注意到这个问题可能是plot()函数 某些数据带有dput() 及 我的代码: data<- read.csv("GranizoAnualCompleto_1961-2019_columnas.csv", header = TRUE) dat_nombres<-read.csv("Nombres_Estaciones_CLICOM.csv",

我试图从一个包含134列的数据库中绘制出许多时间序列,每列一个ts,然后将其保存在一个.jpg文件中。我正在使用一个循环。我注意到这个问题可能是
plot()
函数

某些数据带有
dput()

我的代码:

  data<- read.csv("GranizoAnualCompleto_1961-2019_columnas.csv", header = 
   TRUE)
    dat_nombres<-read.csv("Nombres_Estaciones_CLICOM.csv", header=TRUE )
    Estaciones<-dat_nombres$ESTACIONES  # List
    Estacionestmp<-data[,-1]

    # Loop

    for (i in seq_along (Estacionestmp)) { 
      serie<-ts(Estacionestmp[,i], start = 1961, frequency = 1)
      mypath<-file.path("C:","00 FENIX","03 Data", "Data_Est_Select_1961- 
       2019", "SeriesTiempo_GranizoAnual",  
                paste("Ts_Granizo4_", Estaciones[i],".jpg", sep = "")) 
      jpeg(filename = mypath)  

      plot(serie,
         col="darkblue",
         main="Días con granizo 1961-2019 \n Estación", Estaciones[i] ,
         cex.main=2,
         sub=paste("Estación",Estaciones[i]),
         cex.sub= 1.5,
         col.main="darkred",
         xlab= "Tiempo",
         ylab= "Días con granizo",
         cex.lab=0.8,
         col.axis= "gray34",
         col.lab= "gray25",
         type= "l"
         )
       dev.off() }
但是,当我只是在循环中编写
plot(serie)
(plot函数中没有任何细节)时,结果没有问题,文件是在我定义的特定路径中创建的。最近,我使用了这段代码,但是在一个有20列的数据框架上,它工作了

为什么plot函数参数中的详细信息会导致错误消息?如何修复创建多个时间序列图的循环?有没有更好的解决办法

非常感谢你

编辑:我发现问题是当我试图更改每个绘图的名称和子节的主节时,
Estaciones[I]
;我以前写过一个
#
来评论它,现在它可以工作了!所以,我把它转换成一个列表

  Estaciones_list<-as.list(Estaciones) 

Estaciones\u列表什么是Estaciones?你只显示Estacionestmp。我编辑了我的问题,你是对的,谢谢。这是循环中文件名的列表。很抱歉请提供数据名称的
dput
。通过列的循环将i定义为列号,但使用i作为行号。看,我刚刚编辑了这个问题,把dput()的信息放进去了;当我试图更改每个情节的名称时,我发现了问题。谢谢很抱歉,我不理解您的评论:“您的循环通过列定义I为列号,但使用I作为行号。”
  data<- read.csv("GranizoAnualCompleto_1961-2019_columnas.csv", header = 
   TRUE)
    dat_nombres<-read.csv("Nombres_Estaciones_CLICOM.csv", header=TRUE )
    Estaciones<-dat_nombres$ESTACIONES  # List
    Estacionestmp<-data[,-1]

    # Loop

    for (i in seq_along (Estacionestmp)) { 
      serie<-ts(Estacionestmp[,i], start = 1961, frequency = 1)
      mypath<-file.path("C:","00 FENIX","03 Data", "Data_Est_Select_1961- 
       2019", "SeriesTiempo_GranizoAnual",  
                paste("Ts_Granizo4_", Estaciones[i],".jpg", sep = "")) 
      jpeg(filename = mypath)  

      plot(serie,
         col="darkblue",
         main="Días con granizo 1961-2019 \n Estación", Estaciones[i] ,
         cex.main=2,
         sub=paste("Estación",Estaciones[i]),
         cex.sub= 1.5,
         col.main="darkred",
         xlab= "Tiempo",
         ylab= "Días con granizo",
         cex.lab=0.8,
         col.axis= "gray34",
         col.lab= "gray25",
         type= "l"
         )
       dev.off() }
      Error in xy.coords(x, y, xlabel, ylabel, log) : 
      'x' and 'y' lengths differ
  Estaciones_list<-as.list(Estaciones)