2

我有这些数据:

> dput(dataF)
structure(list(key_date = c("2016-09-01", "2016-09-01", "2016-09-01", 
"2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", 
"2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", 
"2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", 
"2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", 
"2016-09-01"), date = c("2016-09-01 00:00:00", "2016-09-01 01:00:00", 
"2016-09-01 02:00:00", "2016-09-01 03:00:00", "2016-09-01 04:00:00", 
"2016-09-01 05:00:00", "2016-09-01 06:00:00", "2016-09-01 07:00:00", 
"2016-09-01 08:00:00", "2016-09-01 09:00:00", "2016-09-01 10:00:00", 
"2016-09-01 11:00:00", "2016-09-01 12:00:00", "2016-09-01 13:00:00", 
"2016-09-01 14:00:00", "2016-09-01 15:00:00", "2016-09-01 16:00:00", 
"2016-09-01 17:00:00", "2016-09-01 18:00:00", "2016-09-01 19:00:00", 
"2016-09-01 20:00:00", "2016-09-01 21:00:00", "2016-09-01 22:00:00", 
"2016-09-01 23:00:00"), PM = c("10.9", "9.8", "9.9", "14.1", 
"13.6", "16.5", "15", "18.5", "18", "17", "16.6", "12", "12.1", 
"18.1", "15.9", "15.9", "16.9", "21.6", "23.5", "40.7", "16.6", 
"12.7", "12.4", "12.2"), site = c("LW2", "LW2", "LW2", "LW2", 
"LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", 
"LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", 
"LW2", "LW2"), code = c("LW2", "LW2", "LW2", "LW2", "LW2", "LW2", 
"LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", 
"LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2"
), airport = structure(c(NA_integer_, NA_integer_, NA_integer_, 
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
NA_integer_), .Label = character(0), class = "factor"), ws = c(NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_), wd = c(NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), 
    tempi = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
    NA_real_), humidity = c(NA_real_, NA_real_, NA_real_, NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
    NA_real_, NA_real_)), .Names = c("key_date", "date", "PM", 
"site", "code", "airport", "ws", "wd", "tempi", "humidity"), row.names = c(NA, 
-24L), class = "data.frame")

看起来不错,但是当我尝试使用 openair 绘制数据时,为什么会出现此错误?

timePlot(dataF, pollutant = c("PM"), group = TRUE, avg.time = "default")

Error in object[[name, exact = TRUE]] : subscript out of bounds
In addition: Warning message:
In checkPrep(mydata, vars, type, remove.calm = FALSE) :
  Detected data with Daylight Saving Time, converting to UTC/GMT

数据有什么问题?有任何想法吗?

4

1 回答 1

3

我想您PMdate使用timeplot(). 中的所有日期时间值都date属于同一天"2016-09-01",而是在 下指定key_date

描述https://www.rdocumentation.org/packages/openair/versions/0.3-8/topics/timePlot 指定数据必须是 a ,带有一列,这在正在考虑的示例中timeplot()data.framedatedate

因此,我使用ymd_hms包中的函数lubridate来处理日期时间格式,date并强制将值输入PM为数字并as.numeric到达

require(lubridate)
library(lubridate)
dataF <-   data.frame(key_date = c("2016-09-01", "2016-09-01", "2016-09-01", 
                            "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", 
                            "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", 
                            "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", 
                            "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", "2016-09-01", 
                            "2016-09-01"), 
                    date =  ymd_hms( c("2016-09-01 00:00:00", "2016-09-01 01:00:00",
                            "2016-09-01 02:00:00", "2016-09-01 03:00:00", "2016-09-01 04:00:00",
                            "2016-09-01 05:00:00", "2016-09-01 06:00:00", "2016-09-01 07:00:00",
                            "2016-09-01 08:00:00", "2016-09-01 09:00:00", "2016-09-01 10:00:00",
                            "2016-09-01 11:00:00", "2016-09-01 12:00:00", "2016-09-01 13:00:00",
                            "2016-09-01 14:00:00", "2016-09-01 15:00:00", "2016-09-01 16:00:00",
                            "2016-09-01 17:00:00", "2016-09-01 18:00:00", "2016-09-01 19:00:00",
                            "2016-09-01 20:00:00", "2016-09-01 21:00:00", "2016-09-01 22:00:00",
                            "2016-09-01 23:00:00")), 
               PM = as.numeric(c("10.9", "9.8", "9.9", "14.1", 
                     "13.6", "16.5", "15", "18.5", "18", "17", "16.6", "12", "12.1", 
                     "18.1", "15.9", "15.9", "16.9", "21.6", "23.5", "40.7", "16.6", 
                     "12.7", "12.4", "12.2")), 
               site = c("LW2", "LW2", "LW2", "LW2", 
                       "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", 
                       "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", 
                       "LW2", "LW2"), 
               code = c("LW2", "LW2", "LW2", "LW2", "LW2", "LW2", 
                       "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", 
                       "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2"),             
         airport = c(NA_integer_, NA_integer_, NA_integer_, 
                        NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                        NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                        NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                        NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                        NA_integer_), 
          ws = c(NA_real_, 
                 NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                 NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                 NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                 NA_real_, NA_real_), 
          wd = c(NA_real_, NA_real_, NA_real_, NA_real_, 
                 NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                 NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                 NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), 
           tempi = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                         NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                         NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                         NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                         NA_real_), 
          humidity = c(NA_real_, NA_real_, NA_real_, NA_real_, 
                       NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                       NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                       NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                       NA_real_, NA_real_)
        ) 

我们检查 的结构dataF

str(dataF)
'data.frame':   24 obs. of  10 variables:
 $ key_date: Factor w/ 1 level "2016-09-01": 1 1 1 1 1 1 1 1 1 1 ...
 $ date    : POSIXct, format: "2016-09-01 00:00:00" "2016-09-01 01:00:00" "2016-09-01 02:00:00" ...
 $ PM      : num  10.9 9.8 9.9 14.1 13.6 16.5 15 18.5 18 17 ...
 $ site    : Factor w/ 1 level "LW2": 1 1 1 1 1 1 1 1 1 1 ...
 $ code    : Factor w/ 1 level "LW2": 1 1 1 1 1 1 1 1 1 1 ...
 $ airport : Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
 $ ws      : num  NA NA NA NA NA NA NA NA NA NA ...
 $ wd      : num  NA NA NA NA NA NA NA NA NA NA ...
 $ tempi   : num  NA NA NA NA NA NA NA NA NA NA ...
 $ humidity: num  NA NA NA NA NA NA NA NA NA NA ...

现在我们绘制

timePlot(dataF, pollutant = "PM", group = TRUE, avg.time = "default", lty = 1)
dev.off()
于 2017-05-29T16:26:00.617 回答