SCM

SCM Repository

[maptools] Annotation of /pkg/R/colslegs.R
ViewVC logotype

Annotation of /pkg/R/colslegs.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 297 - (view) (download)

1 : rsbivand 3 # Copyright 2000-2001 (c) Nicholas Lewin-Koh
2 :     # modifications 2001-2003 (c) Roger Bivand
3 : rsbivand 297 # modifications 201506 Nick Bearman
4 : rsbivand 3
5 :    
6 :     # Returns a vector of HSV values
7 :     # modifications 2003 (c) Renaud Lancelot
8 :     color.ramp <- function (nclass, color = "red", nvec = NULL, type = "q"){
9 :     eq.split <- function(ncl){
10 :     mult <- rep((1 / ncl), (ncl - 1))
11 :     mult * seq(1, (ncl - 1))
12 :     }
13 :     color.list <- list(cname = c("blue", "green", "yellow", "red"), hsvcol = c(0.7, 0.375, 0.19, 0))
14 :     cind <- match(color, color.list$cname)
15 :     ### change from "if(nvec)" to "if(!is.null(nvec))"
16 :     if(!is.null(nvec)){
17 :     if(type == "q"){
18 :     pr <- eq.split(nclass)
19 :     ### changes in min, quantile and max
20 :     brks <- c(min(nvec, na.rm = TRUE),
21 :     quantile(nvec, pr, names = FALSE, na.rm = TRUE),
22 :     max(nvec, na.rm = TRUE))
23 :     brks <- unique(brks)
24 :     classvec <- cut(nvec, brks, labels = FALSE, include.lowest = TRUE)
25 :     ramp <- hsv(rep(color.list$hsvcol[cind], nclass), c(pr, 1))
26 :     return(list(ramp = ramp, col.class = classvec, breaks=brks))
27 :     }
28 :     else
29 :     if(type == "e"){
30 :     pr <- eq.split(nclass)
31 :     ### changes in min, range and max
32 :     brks <- c(min(nvec, na.rm = TRUE),
33 :     pr * diff(range(nvec, na.rm = TRUE)),
34 :     max(nvec, na.rm = TRUE))
35 :     brks <- unique(brks)
36 :     classvec <- cut(nvec, brks, labels = FALSE, include.lowest = TRUE)
37 :     ramp <- hsv(rep(color.list$hsvcol[cind], nclass), c(pr, 1))
38 :     return(list(ramp = ramp, col.class = classvec, breaks=brks))
39 :     }
40 :     }
41 :     return(NULL)
42 :     }
43 :    
44 : rsbivand 297 #updated leglabs function to allow order of entries to be reversed
45 :    
46 :     leglabs <- function(vec, under="under", over="over", between="-", reverse = FALSE) {
47 :     x <- vec
48 :     lx <- length(x)
49 :     if(lx < 3) stop("vector too short")
50 :     if(reverse) { #if user asks order to be reversed
51 :     #reorder variable
52 :     # x<-reverseorder(x)
53 :     x<-rev(x)
54 :     #set new under and over values
55 :     under <- "over"
56 :     over <- "under"
57 :     }
58 :     res <- character(lx-1)
59 :     res[1] <- paste(under, x[2])
60 :     for (i in 2:(lx-2)) res[i] <- paste(x[i], between, x[i+1])
61 :     res[lx-1] <- paste(over, x[lx-1])
62 :     res
63 : rsbivand 3 }
64 :    
65 : rsbivand 297 #reverseorder <- function(old.var){
66 :     #function to reverseorder any set of values, designed for use with legends in maptools library
67 :     #copy variable to be reordered
68 :     # new.var <- old.var
69 :     #loop going through each value in turn
70 :     # for (i in 1:length(old.var)) {
71 :     #save it in the appropiate place in the new variable
72 :     # new.var[length(old.var)+1-i] <- old.var[i]
73 :     # }
74 :     #return new variable
75 :     # return(new.var)
76 :     #}
77 :    
78 :     #x
79 :    
80 :     #x
81 : rsbivand 3 #The set of classification methods is large (Dent p. 145), but there are a few to remember:
82 :    
83 :     # * Equal Intervals ("Constant Interval"): each class has same difference in value
84 :     # * Quantile (N-tile): each class has same number of units
85 :     # * Natural Breaks: visual examination; manual determination
86 :    
87 :     # Then a lot of ones that you might need to use once in a while
88 :     # Arithmetic progression: constant increase (decrease) in "width" of class
89 :     # Geometric progression: constant multiplier used to derive width of class
90 :     # Jenk's Iterative ("optimal") minimize within class standard deviations (variance) [ESRI calls this "natural breaks"]
91 :     # (see Dent 147-149 on use of F-ratio and weighting)
92 :     # Arbitrary breaks: given externally (laws, regulations, natural process)
93 :     # Standard deviations: statistical distribution
94 :     # Nested Means works by successive halving at the mean (2,4,8,16, ...)
95 :    
96 :     #(Chrisman)
97 :    
98 :    
99 :    

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge