I have these data:
> 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")
It seems fine but why do I get this error when I try to plot the data with 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
What is wrong with the data? Any ideas?
I suppose you want to plot the PM
values against the date
ones, using timeplot()
. All date-time values in date
belong to the same day "2016-09-01"
, which is specified under key_date
, instead.
The timeplot()
description https://www.rdocumentation.org/packages/openair/versions/0.3-8/topics/timePlot
specifies that data have to be a data.frame
, with a date
column, which is date
in the example under consideration.
Therefore I use the fucntion ymd_hms
from the package lubridate
for handling date-time format in date
and I force the values in PM
to be numeric with as.numeric
arriving at
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_)
)
We check the structure of 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 ...
Now we plot
timePlot(dataF, pollutant = "PM", group = TRUE, avg.time = "default", lty = 1)
dev.off()