Re: [R] combineLimits and Dates
On 2012-06-25 15:30, Duncan Mackay wrote: Hi Elliot This works on Win 7 ver 2.15 useOuterStrips(combineLimits( xyplot(x + y ~ d | g, groups = h, data = dat, type = 'l', scales = list(y = list(relation = free), x = list( at =seq(from = as.Date(2011-01-01), to = as.Date(2011-10-01), by = 3 month), labels = format(seq(from = as.Date(2011-01-01), to = as.Date(2011-10-01), by = 3 month), %b)) ), auto.key = TRUE) )) This works because the x-limits don't require combining in this example; all panels have the same xlims. See below for a solution when the xlims are not equal. amend the seq as required and the format if required see ?strptime for format HTH Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 02:28 26/06/2012, you wrote: I'm having some trouble using the latticeExtra 'combineLimits' function with a Date x-variable: require(lattice) set.seed(12345) dates- seq(as.Date(2011-01-01), as.Date(2011-12-31), days) dat- data.frame(d = rep(dates, 4), g = factor(rep(rep(c(1,2), each = length(dates)), 2)), h = factor(rep(c(a, b), each = length(dates)*2)), x = rnorm(4 * length(dates)), y = rnorm(4 * length(dates))) plt1- xyplot(x + y ~ d | g, groups = h, data = dat, type = 'l', scales = list(relation = free), auto.key = TRUE) plt1- useOuterStrips(plt1) plt1- combineLimits(plt1) The x-axis labels are right after the call to 'useOuterStrips' but they get converted to numeric after the call to 'combineLimits'. How do I keep them as date labels? After combineLimits(plt1), the plt1 object will have an x.limits component that has the dates converted to numeric form. You can just modify that component with: plt1$x.limits - lapply(plt1$x.limits, as.Date, origin = 1970-01-01) and then plot it. Peter Ehlers Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] combineLimits and Dates
I'm having some trouble using the latticeExtra 'combineLimits' function with a Date x-variable: require(lattice) set.seed(12345) dates - seq(as.Date(2011-01-01), as.Date(2011-12-31), days) dat - data.frame(d = rep(dates, 4), g = factor(rep(rep(c(1,2), each = length(dates)), 2)), h = factor(rep(c(a, b), each = length(dates)*2)), x = rnorm(4 * length(dates)), y = rnorm(4 * length(dates))) plt1 - xyplot(x + y ~ d | g, groups = h, data = dat, type = 'l', scales = list(relation = free), auto.key = TRUE) plt1 - useOuterStrips(plt1) plt1 - combineLimits(plt1) The x-axis labels are right after the call to 'useOuterStrips' but they get converted to numeric after the call to 'combineLimits'. How do I keep them as date labels? Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] combineLimits and Dates
Hi Elliot This works on Win 7 ver 2.15 useOuterStrips(combineLimits( xyplot(x + y ~ d | g, groups = h, data = dat, type = 'l', scales = list(y = list(relation = free), x = list( at =seq(from = as.Date(2011-01-01), to = as.Date(2011-10-01), by = 3 month), labels = format(seq(from = as.Date(2011-01-01), to = as.Date(2011-10-01), by = 3 month), %b)) ), auto.key = TRUE) )) amend the seq as required and the format if required see ?strptime for format HTH Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 02:28 26/06/2012, you wrote: I'm having some trouble using the latticeExtra 'combineLimits' function with a Date x-variable: require(lattice) set.seed(12345) dates - seq(as.Date(2011-01-01), as.Date(2011-12-31), days) dat - data.frame(d = rep(dates, 4), g = factor(rep(rep(c(1,2), each = length(dates)), 2)), h = factor(rep(c(a, b), each = length(dates)*2)), x = rnorm(4 * length(dates)), y = rnorm(4 * length(dates))) plt1 - xyplot(x + y ~ d | g, groups = h, data = dat, type = 'l', scales = list(relation = free), auto.key = TRUE) plt1 - useOuterStrips(plt1) plt1 - combineLimits(plt1) The x-axis labels are right after the call to 'useOuterStrips' but they get converted to numeric after the call to 'combineLimits'. How do I keep them as date labels? Thanks. - Elliot -- Elliot Joel Bernstein, Ph.D. | Research Associate | FDO Partners, LLC 134 Mount Auburn Street | Cambridge, MA | 02138 Phone: (617) 503-4619 | Email: elliot.bernst...@fdopartners.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.