Michael Sumner
2013-Apr-12 11:27 UTC
[Rd] support for POSIXct classes in image.default axes
Hello, I would like to suggest the following change to image.default in src\library\graphics\R\image.R: 98c98 < plot(NA, NA, xlim = xlim, ylim = ylim, type = "n", xaxs = xaxs, ---> plot(x[1], y[1], xlim = xlim, ylim = ylim, type = "n", xaxs = xaxs,This provides all the support of axis.POSIXt that plot.default gives, currently the default new plot in image.default uses NAs and the axis class is ignored. This is nice for plotting time series data stored in a matrix. Here's a dummy example that shows usage with my change: data(volcano) x <- list(x = Sys.time() + seq(1, 1e6, length = nrow(volcano)), y 1:ncol(volcano), z = volcano) ## date-time formatting on the x-axis image(x) ## date-time formatting on the y-axis image(x$y, x$x, t(x$z)) Without the change we get the very large underlying numeric values for the times on the axis. We can still override the default axis to do a workaround: : image(x, axes = FALSE) axis.POSIXct(x$x, side = 1) Cheers, Mike. -- Michael Sumner Hobart, Australia e-mail: mdsumner@gmail.com [[alternative HTML version deleted]]
Prof Brian Ripley
2013-Apr-17 08:15 UTC
[Rd] support for POSIXct classes in image.default axes
On 12/04/2013 12:27, Michael Sumner wrote:> Hello, I would like to suggest the following change to image.default in > src\library\graphics\R\image.R: > > 98c98 > < plot(NA, NA, xlim = xlim, ylim = ylim, type = "n", xaxs = xaxs, > --- >> plot(x[1], y[1], xlim = xlim, ylim = ylim, type = "n", xaxs = xaxs, >I think xlim, ylim is a better idea: this relies on range() preserving the class. Done now (in R-devel pro tem).> This provides all the support of axis.POSIXt that plot.default gives, > currently the default new plot in image.default uses NAs and the axis class > is ignored. This is nice for plotting time series data stored in a matrix. > > Here's a dummy example that shows usage with my change: > > data(volcano) > x <- list(x = Sys.time() + seq(1, 1e6, length = nrow(volcano)), y > 1:ncol(volcano), z = volcano) > > ## date-time formatting on the x-axis > image(x) > > ## date-time formatting on the y-axis > image(x$y, x$x, t(x$z)) > > Without the change we get the very large underlying numeric values for the > times on the axis. > > We can still override the default axis to do a workaround: : > image(x, axes = FALSE) > axis.POSIXct(x$x, side = 1) > > Cheers, Mike. > > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595