1

I have a raster in .tif format which I am trying to visualize in R using levelplot. Here is what I have done so far:

library(raster)
library(lattice)

data_tif <- raster("fthrt14_21.tif", RAT = TRUE)
data_tif

rat <- read.dbf("fthrt14_21.tif.vat.dbf")
rat
data_tif <- ratify(data_tif)
colnames(rat)[1] <- "ID"
levels(data_tif) <- rat


levelplot(data_tif, col.regions=rev(terrain.colors(5)),main = "Fire Threats"
          , attr(THRT_CLASS))

I am getting an error: Error in UseMethod("levelplot") : no applicable method for 'levelplot' applied to an object of class "c('RasterLayer', 'Raster', 'BasicRaster')"

How can I resolve this error? This is what my RAT looks like: enter image description here

2 Answers 2

1

For the levelplot function to plot a raster, you need to install the "rasterVis" package first.

0

Its got nothing to do with the raster being categorical - there is no levelplot function for any type of raster in the raster or lattice packages:

> library(raster)
> library(lattice)
> r = raster(matrix(runif(100),10,10))
> levelplot(r)
Error in UseMethod("levelplot") : 
  no applicable method for 'levelplot' applied to an object of class "c('RasterLayer', 'Raster', 'BasicRaster')"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.