Relassify continuous raster data into binned classes with discrete colors

孤人 提交于 2019-12-04 06:18:31

You can cut your raster, and then specify the colour breaks with at, and the colorkey breaks with a list containing at and labels, passed to the colorkey arg:

    levelplot(cut(ras, 9), col.regions=col, 
              at=0:9, margin=FALSE,
              colorkey=list(labels=list(at=0:8 + 0.5, labels=levels(cut(ras[], 9)))))

Above, we are saying that we want to split ras into 9 equal-width bins. These bins will be denoted by the numbers 1 through 9, and at=0:9 specifies that we want colours to change at values 0 through 9. To label the colorkey correctly, we pass a list called labels, with argument at indicating where we want the labels to be located, and argument labels providing the corresponding labels. Note that you can pass whatever you want to the labels element of the labels list passed to the colorkey argument (e.g. to match the format of your example plot, you might want to use something like labels=list(at=0:8 + 0.5, labels=sub('\\((.+),(.+)]', '>\\1 ~ \\2', levels(cut(ras[], 9))))).

You could instead use ratify to coerce the raster layer to a factor, and set the factor levels to the desired label text, but this can be a bit fiddly if levels are missing.

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