0

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"])]
if(length(new.packs)) install.packages(new.packs)
lapply(kpacks, require, character.only=T)
remove(kpacks, new.packs)
options(max.print=5.5E5) 

#World data
wlist <- list.files(pattern = "\\.tif$", include.dirs = TRUE)
s <- lapply(wlist, stack)

levelplot(s)

Error:

Error in UseMethod("levelplot") : 
  no applicable method for 'levelplot' applied to an object of class "list"

Note:

I can see the figure for individual geoTiff files:

levelplot(s[[1]]), for example

One of the files: https://www.dropbox.com/s/ank4uxjbjk3chaz/new_conus.tif?dl=0

maximusdooku
  • 5,242
  • 10
  • 54
  • 94
  • what about `lapply(s, levelplot)`? – HubertL Oct 11 '16 at 20:35
  • That works. But I don't get the monthly panel. Instead it plots each tif file separately. I wanted something like the first figure on this page: https://oscarperpinan.github.io/rastervis/ – maximusdooku Oct 11 '16 at 20:38

1 Answers1

1

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.

Example

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)
Jeffrey Evans
  • 2,325
  • 12
  • 18