I have 12 raster files in a folder on which I want to use the levelplot of RasterVis.
kpacks <- c('tiff','rgdal','raster','sp','rasterVis')
new.packs <- kpacks[!(kpacks %in% installed.packages()[,"Package"])]
lapply(kpacks, require, character.only=T)
wlist <- list.files(pattern = "\\.tif$", include.dirs = TRUE)
s <- lapply(wlist, stack)
Error in UseMethod("levelplot") :
no applicable method for 'levelplot' applied to an object of class "list"
levelplot(s[]), for example
You do not need to coerce the rasters to a list object, which is what is causing you issues, or use lapply for plotting multiple rasters with levelplot. Use stack or brick for reading your data and then just pass the object to levelplot.
library(raster) library(rasterVis) s <- stack(system.file("external/rlogo.grd", package="raster")) levelplot(s, contour=TRUE)
With your code
s <- stack( list.files(pattern = "\\.tif$", include.dirs = TRUE) ) levelplot(s)