as.POSIXlt.character 中的 Dygraphs 错误

Dygraphs error in as.POSIXlt.character

正在尝试使用 dygraphs 包创建图表。我已经使用 as.Date() 转换了日期,但我收到了这条消息:

Error in as.POSIXlt.character(x, tz, ...) : 
  character string is not in a standard unambiguous format

我的数据的前几行如下所示:

          Date   Depth      Fecal.Coliform Dissolved.Oxygen
1   1992-05-02   0.5            6.0               NA
2   1992-05-15   0.5             NA         9.900000
3   1992-05-31   0.5             NA         8.800000
4   1992-06-11   0.5             NA         8.900000

dygraphs 似乎更喜欢时间序列数据而不是日期。尝试使用 xts:

转换您的日期
library(xts)
library(dygraphs)

data <- data.frame(Date  = as.Date(c("1992-05-02", "1992-05-15",
                                   "1992-05-31", "1992-06-11")),
                   Depth = c(0.5, 0.5, 0.5, 0.5),
          Fecal.Coliform = c(6.0, NA, NA, NA),
        Dissolved.Oxygen = c(NA, 9.900000, 8.800000, 8.900000))

# This produces your error
dygraph(data)

# convert your data to time series and plot it!
new.data <- cbind(xts(data$Dissolved.Oxygen, data$Date),
                      data$Fecal.Coliform, data$Depth)
colnames(new.data) <- c("Dissolved.Oxigen", "Fecal.Coliform", "Depth")
dygraph(new.data)