我有这些数据:
> 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
数据有什么问题?有什么想法吗?
答案 0 :(得分:3)
我想您想使用PM
将date
值与timeplot()
值进行对比。 date
中的所有日期时间值都属于同一天"2016-09-01"
,而key_date
则指定在timeplot()
下。
data.frame
说明https://www.rdocumentation.org/packages/openair/versions/0.3-8/topics/timePlot
指定数据必须为date
,且date
列,在所考虑的示例中为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_)
)
1}}到达
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()
现在我们绘制
if (item.limit != null || item != ' ' && now.isAfter(dateLimit) ) {