Aviad Klein
2011-Feb-19 16:44 UTC
[R] problem in plotting numeric x by POSIXt class with lattice
# hi all, # I'm trying to plot temperatures by date in a trellis plot by their stations # I'm plotting the following data.frame library(lattice) h <- structure(list(station_name = structure(c(3L, 4L, 2L, 10L, 11L, 12L, 6L, 7L, 5L, 8L, 9L, 3L, 4L, 2L, 10L, 11L, 12L, 6L, 7L, 5L, 8L, 9L, 3L, 4L, 2L, 10L, 11L, 12L, 6L, 7L), .Label = c("Ashqelon", "Beer Sheva", "Beit Dagan", "Eden", "Ein Carmel", "Jerusalem", "Negba", "Nir HaEmek", "Ramat HaNegev", "Ramon", "Tel Mond", "Zemah"), class = "factor"), max_dry = c(23.4, 24.3, 25.5, 21.8, 23.1, 22, 23, 24, 22.7, 24.9, 23.3, 20.2, 20.8, 22.5, 20, 20.6, 20.5, 20.9, 21, 19.2, 21.8, 20.7, 21, 21.8, 20.2, 18.4, 20.5, 20.3, 17.1, 21.4), measure_date = structure(list(sec = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), hour = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), mday = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), mon = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), year = c(100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100), wday = c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), yday = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("sec", "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"), class = c("POSIXlt", "POSIXt" ))), .Names = c("station_name", "max_dry", "measure_date"), row.names c(NA, 30L), class = "data.frame") # using the following : xyplot(max_dry~measure_date|station_name,data=h) # I receive the following error # Error in structure(xx, class = c("POSIXct", "POSIXt"), tzone = tz) : invalid 'x' argument # does anyone know why? # thanks [[alternative HTML version deleted]]
David Winsemius
2011-Feb-19 16:51 UTC
[R] problem in plotting numeric x by POSIXt class with lattice
On Feb 19, 2011, at 11:44 AM, Aviad Klein wrote:> # hi all, > > # I'm trying to plot temperatures by date in a trellis plot by their > stations > > # I'm plotting the following data.frame > > library(lattice) > > h <- structure(list(station_name = structure(c(3L, 4L, 2L, 10L, 11L, > 12L, 6L, 7L, 5L, 8L, 9L, 3L, 4L, 2L, 10L, 11L, 12L, 6L, 7L, 5L, > 8L, 9L, 3L, 4L, 2L, 10L, 11L, 12L, 6L, 7L), .Label = c("Ashqelon", > "Beer Sheva", "Beit Dagan", "Eden", "Ein Carmel", "Jerusalem", > "Negba", "Nir HaEmek", "Ramat HaNegev", "Ramon", "Tel Mond", > "Zemah"), class = "factor"), max_dry = c(23.4, 24.3, 25.5, 21.8, > 23.1, 22, 23, 24, 22.7, 24.9, 23.3, 20.2, 20.8, 22.5, 20, 20.6, > 20.5, 20.9, 21, 19.2, 21.8, 20.7, 21, 21.8, 20.2, 18.4, 20.5, > 20.3, 17.1, 21.4), measure_date = structure(list(sec = c(0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0), min = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L), hour = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L), mday = c(1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), mon = c(0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), year = c(100, 100, 100, > 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, > 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, > 100), wday = c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, > 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, > 5L, 5L), yday = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, > 0L, 0L, 0L, 0L)), .Names = c("sec", "min", "hour", "mday", "mon", > "year", "wday", "yday", "isdst"), class = c("POSIXlt", "POSIXt" > ))), .Names = c("station_name", "max_dry", "measure_date"), > row.names > c(NA, > 30L), class = "data.frame") > > # using the following : > > xyplot(max_dry~measure_date|station_name,data=h) > > # I receive the following error > # Error in structure(xx, class = c("POSIXct", "POSIXt"), tzone = tz) : > invalid 'x' argument > > # does anyone know why?POSIXlt dates are not always handled well by plotting routines. Try: > h$measure_date <- as.POSIXct(h$measure_date) > xyplot(max_dry ~ measure_date | station_name, data=h) -- David Winsemius, MD West Hartford, CT