问题
I am doing a idw interpolation between several air quality stations. For the final visualization I want to collapse all the images I made into a GIF. Everything works, the only problem is that the scales of values change in every image, and the scale changes with the values (min - max). How do I set the scale of the colors to a fixed value?
Here's some sample data:
data(meuse.grid)
coords <- SpatialPixels(SpatialPoints(meuse.grid[,c('x',"y")]))
meuseg1 <- SpatialPixelsDataFrame(coords,meuse.grid)
meusedist1 <- SpatialPixelsDataFrame(coords,data=data.frame(meuseg1@data$dist))
meusedist2 <- SpatialPixelsDataFrame(coords,data=data.frame(meuseg1@data$dist*2))
spplot(meusedist1)
spplot(meusedist2)
What I'm looking for is that the scale on both plots have the same range of values, so the colors in the plots should scale to the largest scale bar (from 0 to 2). It sounds not that complicated and I'm sure it is possible and not that hard, but for some reason I can't find it or figure it out.
Thanks!
回答1:
Try using the at
attribute to fix the color breaks:
spplot(meusedist1, at = seq(0,2,.1))
alternatively, a single (shared) legend is created by:
meuseg1$dist2 = meuseg1$dist * 2
spplot(meuseg1, c("dist", "dist2"))
来源:https://stackoverflow.com/questions/35728194/how-do-i-fix-a-color-scale-bar-in-several-spplots