Learn R Programming

phalen (version 1.0)

wash: Wash Color Palette

Description

Color Palette for R.

Usage

wash(color, grade)

Arguments

color
Name of the color or color vector to be returned. Run wash.showall() or see details for a complete list of accepted color arguments.
grade
A positive numeric value. For grade between 0 and 1, a single color of gradient grade will be returned. For grade between 1 and 61, a character vector of N equidistant grandients will be returned.

Value

A color or vector of colors.

Details

Use wash.showall() to see the list of colors available and to return 15 of the 61 color gradients. Below is a list of all colors:

"grd1" green to red, vibrant

"grd2" green to red, pale

"blu1" blue

"blu2" dark blue

"grn1" lime green

"grn2" green

"ylw" yellow

"org" orange

"red1" orange to red

"red2" pink to red

"prp1" purple

"prp2" dark purple

"cyn" cyan

"grb" grey blue

"gry" grey

See Also

washout

Examples

Run this code
  # 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)

Run the code above in your browser using DataLab