How do I fix a color scale bar in several spplots?

梦想的初衷 提交于 2019-12-10 22:12:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!