Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

plot

r

r-sp

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!

like image 926
ArnJac Avatar asked Nov 23 '25 21:11

ArnJac


1 Answers

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"))
like image 97
Edzer Pebesma Avatar answered Nov 26 '25 13:11

Edzer Pebesma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!