0

我正在尝试使用hydroplotpackage hydroTSM,但出现以下错误:

Error in UseMethod("time<-") : no applicable method for 'time<-' applied to an object of class "zoo"

我用过这段代码:

    td<-seq(as.Date("2009/02/12"), as.Date("2013/07/11"), "days") 
    Tempzoo = zoo(x=Temp, order.by=td)

    hydroplot(Tempzoo, na.rm=TRUE, ptype="ts+boxplot+hist", pfreq="dma",                      
      var.type="Temperature", var.unit="units", main=NULL, xlab="Time", ylab="Temp",
      win.len1=0, win.len2=0, tick.tstep="auto", lab.tstep="auto", 
      lab.fmt=NULL, cex=0.3, cex.main=1.3, cex.lab=1.3, cex.axis=1.3, 
      col=c("blue", "lightblue", "lightblue"), stype="default", season.names=c("Winter", "Spring", "Summer", "Autumn"), 
      h=NULL)

以下是我的数据集的一个子集:

    2009-02-12 2009-02-13 2009-02-14 2009-02-15 2009-02-16 2009-02-17 2009-02-18 
      3.535849   3.505208   3.973958   4.398958   4.004167   4.175000   5.598958 
    2009-02-19 2009-02-20 2009-02-21 2009-02-22 2009-02-23 2009-02-24 2009-02-25 
      5.507292   5.245833   5.639583   5.988542   6.458333   6.567708   5.811458 
    2009-02-26 2009-02-27 2009-02-28 2009-03-01 2009-03-02 2009-03-03 2009-03-04 
      5.533333   5.976042   6.027083   6.112500   5.576042   5.176042   5.326042 
    2009-03-05 2009-03-06 2009-03-07 2009-03-08 2009-03-09 2009-03-10 2009-03-11 
      4.746875   4.485417   4.975000   4.960417   4.829167   4.942708   5.175000 
    2009-03-12 2009-03-13 2009-03-14 2009-03-15 2009-03-16 2009-03-17 2009-03-18 
      5.789583   6.137500   6.628125   6.755208   7.046875   6.864583   7.033333 
    2009-03-19 2009-03-20 2009-03-21 2009-03-22 2009-03-23 2009-03-24 2009-03-25 
      7.427083   7.191667   7.229167   6.740625   6.194792         NA   6.117708 
    2009-03-26 2009-03-27 2009-03-28 2009-03-29 2009-03-30 2009-03-31 2009-04-01 
      6.702083   6.268750         NA   5.797917   6.637500   7.918750   8.744792 
    2009-04-02 2009-04-03 2009-04-04 2009-04-05 2009-04-06 2009-04-07 2009-04-08 
            NA         NA         NA   7.330208   7.075000         NA         NA 
    2009-04-09 2009-04-10 2009-04-11 2009-04-12 2009-04-13 2009-04-14 2009-04-15 
            NA         NA         NA         NA   9.031250   8.687500   8.841667 
    2009-04-16 2009-04-17 2009-04-18 2009-04-19 2009-04-20 2009-04-21 2009-04-22 
      9.947917   8.946875   8.512500   9.478125         NA  10.075000         NA 
   2009-04-23 2009-04-24 2009-04-25 2009-04-26 2009-04-27 2009-04-28 2009-04-29 
            NA         NA   9.272917   9.511458         NA   9.295833   9.764583 

关于如何解决这个问题的任何想法?谢谢!

4

1 回答 1

2

搜索了您的错误消息,并尝试了@Roland 提供的解决方案。timeSeries是的,当您尝试绘图时,似乎已经加载了包。这是一个例子:

library(zoo)
library(hydroTSM)

# create data
td <- seq(as.Date("2009/02/12"), as.Date("2013/07/11"), "days") 
n <- length(td)
Temp <- sample(c(rnorm(n, mean = 10), rep(NA, n/5)), n)
Tempzoo <- zoo(x = Temp, order.by = td)


# in addition, load the suspected package ‘timeSeries’ 
library(timeSeries)
# Attaching package: ‘timeSeries’
# 
# The following object is masked from ‘package:zoo’:
#   
#   time<-

# try plot
hydroplot(x = Tempzoo,
          na.rm = TRUE,
          ptype = "ts+boxplot+hist",
          pfreq = "dma",                      
          var.type = "Temperature",
          var.unit = "units",
          main = NULL,
          xlab = "Time", ylab = "Temp",
          win.len1 = 0, win.len2 = 0,
          tick.tstep = "auto", lab.tstep = "auto", 
          lab.fmt = NULL,
          cex = 0.3, cex.main = 1.3, cex.lab = 1.3, cex.axis = 1.3, 
          col=c("blue", "lightblue", "lightblue"), stype="default",
          season.names = c("Winter", "Spring", "Summer", "Autumn"), 
          h=NULL)

# Error in UseMethod("time<-") : 
#   no applicable method for 'time<-' applied to an object of class "zoo"

# i.e. your error

# detach ‘timeSeries’ 
detach(package:timeSeries)

# plot again

在此处输入图像描述

于 2013-10-03T17:04:22.220 回答