[R-sig-Geo] Legend problem with levelplot and categorical rasters

Oscar Perpiñán Lamigueiro oscar.perpinan at gmail.com
Wed Feb 27 11:09:32 CET 2013


Hello,

This is a bug in rasterVis::levelplot. The ticks locations of the legend are incorrectly
calculated. I will try to fix it as soon as possible.

Best,

Oscar.
Alastair Potts <potts.a at gmail.com> writes:

> Good day all,
>
> I can't seem to wrap my head around why this is not working. Below are two
> examples of plotting a categorical raster. The first has a continuous
> series of integers (i.e. 1,2,3) whereas the second has breaks (i.e. 1,3,5).
> The legend in the second levelplot example is incorrect as it seems to be
> expecting a continuous series. I have very good reasons to have a broken
> series and would very much like to have to avoid recoding the to a
> continuous series.
>
> Any suggestions would be greatly appreciated. Thanks in advance.
>
> Examples below.
>
> ## Example 1
> library(raster)
> library(rasterVis)
> ## Categorical data
> r <- raster(nrow=10, ncol=10)
> r[] = 1
> r[51:100] = 2
> r[3:6, 1:5] = 3
> r <- ratify(r)
>
> rat <- levels(r)[[1]]
> rat$landcover <- c('Pine', 'Oak', 'Meadow')
> levels(r) <- rat
> r
> levelplot(r, col.regions=c('palegreen', 'midnightblue', 'indianred1'))
>
> ## Example 2
> ## Categorical data
> r <- raster(nrow=10, ncol=10)
> r[] = 1
> r[51:100] = 3
> r[3:6, 1:5] = 5
> r <- ratify(r)
>
> rat <- levels(r)[[1]]
> rat$landcover <- c('Pine', 'Oak', 'Meadow')
> levels(r) <- rat
> r
> levelplot(r, col.regions=c('palegreen', 'midnightblue', 'indianred1'))


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan



More information about the R-sig-Geo mailing list