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 at 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.pebesma at wwu.de