Skip to content

equal spacing of the polygons in levelplot key (lattice)

5 messages · Dennis Murphy, Andy Bunn

#
Given the example:
R> (levs <- quantile(volcano,c(0,0.1,0.5,0.9,0.99,1)))
   0%  10%  50%  90%  99% 100% 
   94  100  124  170  189  195 
R> levelplot(volcano,at=levs)

How can I make the key categorical with the size of the divisions equally spaced in the key? E.g., five equal size rectangles with labels at levs c(100,124,170,189,195)? 

Apologies if this is obvious. 

-A

R> version
                _                            
 platform       i386-pc-mingw32              
 arch           i386                         
 os             mingw32                      
 system         i386, mingw32                
 status                                      
 major          2                            
 minor          14.0                         
 year           2011                         
 month          10                           
 day            31                           
 svn rev        57496                        
 language       R                            
 version.string R version 2.14.0 (2011-10-31)
#
Hi:

Does this work?

# library('lattice')
levs <- as.vector(quantile(volcano,c(0,0.1,0.5,0.9,0.99,1)))
levelplot(volcano, at = levs,
            colorkey = list(labels = list(at = levs,
                                                   labels = levs) ))

HTH,
Dennis
On Tue, Nov 15, 2011 at 1:12 PM, Andy Bunn <Andy.Bunn at wwu.edu> wrote:
#
Thanks Dennis.

This almost works. Is there a way to make the rectangles in the key the same size? In this example five rectangles of the same area evenly arrayed? Can the key be coerced into being categorical?

The data I want to work with are not spatial but it occurs to me that this is a common mapping task (e.g., in this example you might want to label these colors 'low', 'kind of low', 'medium low', etc. or map land covers or such.) I'll look at the sp or raster plotting equivalent.
#
OK, how about this instead?

# library('lattice')
levs <- as.vector(quantile(volcano,c(0,0.1,0.5,0.9,0.99,1)))
levq <- seq(min(levs), max(levs), length = 6)
levelplot(volcano, at = levs,
           colorkey = list(at = levq,
                                 labels = list(at = levq,
                                                   labels = levs) ))

Dennis
On Wed, Nov 16, 2011 at 10:27 AM, Andy Bunn <Andy.Bunn at wwu.edu> wrote:
#
Whoa. Tricky. That's great. Thanks!