washout: Wash Out

Description Usage Arguments Details Value See Also Examples

View source: R/washout.R

Description

Fit color vector to data.

Usage

1
washout(x, washcol, method = "index")

Arguments

x

A vector. For method = "value", a numeric vector must be supplied.

washcol

A vector of colors.

method

Accepts "index" or "value". The default is "index".

Details

washout assigns a washcol color to each element in vector x. For method = "index", each color element in washcol is evenly applied to vector x based on the index of vector x. For method = "value", each color element in washcol is evenly applied to vector x based on the value of vector x.

Value

washout returns a character color vector of length x.

See Also

wash

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  # show all colors
  wash.showall()
  
  # ---------------------------------------------
  # Chose a single color: 
  # ---------------------------------------------
  # Specify the color then specify a gradient 0-1.  
  # Here is purple2 at 30%
  washcol = wash('prp2',0.3)
  plot(1,1,col = washcol,cex = 21,pch=16,axes = FALSE,xlab = "",ylab = "")
  
  # purple2 at 100%
  washcol = wash('prp2',1)
  plot(1,1,col = washcol,cex = 21,pch=16,axes = FALSE,xlab = "",ylab = "")
  
  
  # ---------------------------------------------
  # Chose a vector of colors: 
  # ---------------------------------------------
  # Specify the color then specify the number of 
  # gradients (1-61) to include in the vector. Here 
  # are 5 shades of blue1. 
  washcol = wash("blu1",5)
  plot(seq.int(1,5),rep(1,5),col = washcol,pch=15,cex = 10
       ,axes = FALSE,xlim = c(0.5,5.5),xlab = "",ylab = "")
  
  # chose 5 different colors
  washcol = c(wash("blu1",1),
              wash("grn2",1),
              wash("ylw",1),
              wash("org",1),
              wash("red2",1))
  plot(seq.int(1,5),rep(1,5),col = washcol,pch=15,cex = 10
       ,axes = FALSE,xlim = c(0.5,5.5),xlab = "",ylab = "")
  
  # 61 shades of greenred1 (for heat maps)
  washcol = wash("grd1",61)
  plot(seq.int(1,61),rep(1,61),col = washcol,pch=15,cex = 21
       ,xlim= c(-4,54),axes = FALSE,xlab = "",ylab = "")
  
  
  # ---------------------------------------------
  # Expand a color vector to match data
  # ---------------------------------------------
  
  # plot readmission by age, no color
  data(ipadmits)
  attach(ipadmits)
  ipadmits.summary = data.frame("AvgReadmission" = tapply(ipadmits$isReadmission
                                                          ,ipadmits$Age
                                                          ,mean)
                               ,"AvgCost" = tapply(ipadmits$cost
                                                  ,ipadmits$Age
                                                  ,mean))
  
  plot(ipadmits.summary$AvgReadmission
       ,xlab = "Age",ylab = "AvgReadmission")
  
  # get vector of 9 greenred1 colors then expand color vector 
  # to match readmission data with color gradient increasing by 
  # value of avg readmission
  washcol = wash("grd1",9)
  washoutcol = washout(ipadmits.summary$AvgReadmission,washcol,method = "value")
  plot(ipadmits.summary$AvgReadmission,col=washoutcol
       ,pch=16,xlab = "Age",ylab = "AvgReadmission")
  
  # increase gradient by the index of the vector Age of value
  washoutcol = washout(ipadmits.summary[,1],washcol,method = "index")
  plot(ipadmits.summary$AvgReadmission,col=washoutcol
       ,pch=16,xlab = "Age",ylab = "AvgReadmission")
  
  # increase gradient by average cost
  washoutcol = washout(ipadmits.summary$AvgCost[1:60]
                      ,washcol, method = "value")
  plot(ipadmits.summary$AvgReadmission[1:60], col=washoutcol
       , pch=16,xlab = "Age", ylab = "AvgReadmission")
  detach(ipadmits)

phalen documentation built on May 29, 2017, 4:22 p.m.

Related to washout in phalen...