Dylan, I believe that lattice (grid) recently improved the plotting of rasters quite a bit, by using panel.levelplot.raster instead of panel.levelplot - some function in grid now renders rasters faster on devices for which this is optimed.
spplot also has to transform the data to long format, by calling sp:::spmap.to.lev, which in turn uses a stack method for SpatialPointsDataFrame objects; this in turn uses stack.data.frame Bests, On 11/08/2010 05:00 AM, Dylan Beaudette wrote: > Interesting demonstration. However, it seems like sp objects and > spplot are still more efficient at storing / plotting large grids. The > example listed below required over 2 minutes to complete on a 2.4 Ghz > Intel processor. Also, storing the coordinates + data in long format > could easily fill available memory with large rasters. I have found > that storing multiple raster attributes as columns in the @data slot > of a SpatialGridDataFrame object give me flexibility to plot images > with a consistent color scheme, without needing to store the data in > long format. Also with lattice, the plots are generated in a couple of > seconds (500x700 px grid). I would be very interested in knowing how > to make ggplot() any faster. > > Cheers! > Dylan > > On Sun, Nov 7, 2010 at 11:55 AM, Edzer Pebesma > <edzer.pebe...@uni-muenster.de> wrote: >> Paul, this nicely illustrates the power of ggplot2. >> >> In the resulting plot, however, it seems to me that the >> >> + opts(aspect.ratio = 1) >> >> does not result in the desired effect that 1 m in the x direction equals >> 1 m in the y direction. Standard plot (asp = 1), and lattice plots (asp >> = "iso") have this; what does ggplot2 need? >> >> On 10/31/2010 11:31 AM, Paul Hiemstra wrote: >>> Hi Peter, >>> >>> When creating such a large amount of illustrations with the same >>> colorscale, I automatically think of lattice graphics. Under the hood >>> spplot also uses lattice graphics. Take a look at the levelplot() >>> function from lattice which produces the grid plots for spplot (if I'm >>> correct). Alternatively, I've been using ggplot now for quite a while to >>> make plots of a lot of grids. A small example says more than a thousand >>> words: >>> >>> library(ggplot2) >>> library(sp) >>> >>> data(meuse.grid) >>> summary(meuse.grid) >>> >>> # Note that I do not transform meuse.grid to SpatialPixelsDataFrame >>> # Let's make a simple grid plot >>> dum = meuse.grid[c("x","y","dist")] >>> ggplot(aes(x = x, y = y, fill = dist), data = dum) + geom_tile() >>> >>> # Let's make a few more attributes to the grid >>> # could be measurements on other dates for example >>> new_atts = do.call("cbind", lapply(1:100, function(num) dum$dist + >>> runif(dum$dist))) >>> summary(new_atts) >>> dum = data.frame(cbind(dum, new_atts)) >>> >>> # Important step now is to >>> # restructure the data >>> dum_ggplot = melt(dum, id.vars = c("x","y")) >>> >>> # Now make a plot using dum_ggplot >>> # of 'x' and 'y' using value as a 'fill' >>> # with a plot per 'variable', can take a minute to plot >>> ggplot(aes(x = x, y = y, fill = value), data = dum_ggplot) + geom_tile() >>> + facet_wrap(~variable) + >>> scale_x_continuous('', labels = NA, breaks = NA) + >>> scale_y_continuous('', labels = NA, breaks = NA) + >>> opts(aspect.ratio = 1) >>> # These last two lines get rid of the labels on the axes and set aspect >>> ratio to 1 >>> >>> Now you have a plot with 101 maps with the same colorscale, with ggplot >>> doing all the hard work. It takes some time to get the hang of ggplot, >>> but I think it is worth the investment, also for spatial plots. >>> >>> cheers and hope this helps, >>> Paul >>> >>> On 10/28/2010 09:12 PM, Peter Larson wrote: >>>> Hello! >>>> >>>> I have a problem. >>>> >>>> I am using IDW to interpolate a daily series of geospatial >>>> observations. Thus, I want to produce a large number of sequential >>>> maps. >>>> >>>> I want them to all represent the same color scale. Is there any way to >>>> fix the color scale so that it is the same for all the plots? >>>> >>>> Thanks, >>>> >>>> Pete >>>> >>>> _______________________________________________ >>>> R-sig-Geo mailing list >>>> R-sig-Geo@stat.math.ethz.ch >>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>> >>> >>> >> >> -- >> Edzer Pebesma >> Institute for Geoinformatics (ifgi), University of Münster >> Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251 >> 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de >> http://www.52north.org/geostatistics e.pebe...@wwu.de >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo@stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of Münster Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebe...@wwu.de _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo