can raster create multi-layer objects with different modes?

↘锁芯ラ 提交于 2019-12-03 08:31:30
mdsumner

The raster package provides the ability to create rasters with a categorical variable, and the rasterVis package includes functions for plotting them. The ratify function allows a raster to include a lookup table relating the underlying raster integer values to other values, which can be character. This directly allows the use of any other mode of value in the levels part of the ratified raster.

Here's an example.

library(rasterVis)


r <- raster(xmn = 0, xmx = 1, ymn = 0, ymx = 2, nrow = 10, ncol = 11, 
            crs = as.character(NA))
r[] <- sample(seq_along(letters[1:5]), ncell(r), replace = TRUE)

## ratify the raster, and set up the lookup table
r <- ratify(r)
rat <- levels(r)[[1]]
rat$value <- letters[1:5]
rat$code <- 1:5

## workaround for limitation as at 2013-05-01
## see https://stat.ethz.ch/pipermail/r-sig-geo/2013-May/018180.html
rat$code <- NULL
levels(r) <- rat

levelplot(r)

There are coming updates to rasterVis that make the workaround above unnecessary.

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