vector - R base plot polygon map with specified z range? -
i'd generate set of maps consistent color ramps , little bit stuck. know how want rasters, not vector data.
here's behavior want rasters:
require(raster) r1=raster(matrix(sample(1:50,16),4,4)) r2=raster(matrix(sample(1:100,16),4,4)) plot(r1,col=colorramppalette(c("red","white","blue"))(10),zlim=c(0,100)) plot(r2,col=colorramppalette(c("red","white","blue"))(10),zlim=c(0,100))
how make similar maps polygons?
for example:
poly1=rastertopolygons(r1) poly2=rastertopolygons(r2)
# previous code... require(raster) r1=raster(matrix(sample(1:50,16),4,4)) r2=raster(matrix(sample(1:100,16),4,4)) poly1=rastertopolygons(r1) poly2=rastertopolygons(r2) ################################################# # color polygons specific z range: # create function generate continuous color palette work rbpal <- colorramppalette(c('red','white','blue')) # make color scale polygons 1 & 2 cutting continuous # palette object (rbpal) 50 discrete blocks. # each of these blocks defined polygon layer # values in sequence ranging 1 100 head(poly1); summary(poly1) poly1$col <- rbpal(50)[as.numeric(cut(poly1$layer, breaks = c(seq(1, 100, by=2))))] poly2$col <- rbpal(50)[as.numeric(cut(poly2$layer, breaks = c(seq(1, 100, by=2))))] head(poly1); head(poly2) # plot par(mfrow=c(1,2)) plot(poly1, col=poly1$col) plot(poly2, col=poly2$col)
Comments
Post a Comment