Custom Colors

David Gerbing

library("lessR")

getcolors()

The getColors() function can generate a variety of color palates. Use them to, for example, fill the bars in a histogram or bar chart with the fill parameter.

Qualitative Scales

The default is a color spectrum of 12 hcl colors presented in the order in which they are assigned to discrete levels of a categorical variable. For clarity, the pal or palette parameter is set to "hues". The colors are generated with the base R hcl() function. To maintain equal brightness/intensity across the colors, all colors are based on chroma set at c=65 and luminance set at l=55.

getColors("hues")

Display the color spectrum of 12 hcl colors ordered by hue from 0 by intervals of 360/12 = 30 degrees.

getColors(in_order=TRUE)

Display a color wheel of 36 ordered hues around the wheel.

getColors(n=36, shape="wheel", border="off")

Obtain deep rich colors for HCL qualitative scale.

getColors(c=90, l=45)

Scales

Generate an hcl blue sequence with c=60 and vary l.

getColors("blues", labels=FALSE)

Vary chroma for a yellow hcl sequence.

getColors("browns", c=c(20,90), l=60)

Divergent Scales

Generate seven colors from rust to blue.

getColors("rusts", "blues", n=7)

Add a custom value of chroma, c, to make less saturated.

getColors("rusts", "blues", n=7, c=45)

Apply to a bar chart. Any call to getColors(), for example, can be applied to the standard fill parameter.

d <- Read("Employee")
## 
## >>> Suggestions
## Details about your data, Enter:  details()  for d, or  details(name)
## 
## Data Types
## ------------------------------------------------------------
## character: Non-numeric data values
## integer: Numeric data values, integers only
## double: Numeric data values with decimal digits
## ------------------------------------------------------------
## 
##     Variable                  Missing  Unique 
##         Name     Type  Values  Values  Values   First and last values
## ------------------------------------------------------------------------------------------
##  1     Years   integer     36       1      16   7  NA  15 ... 1  2  10
##  2    Gender character     37       0       2   M  M  M ... F  F  M
##  3      Dept character     36       1       5   ADMN  SALE  SALE ... MKTG  SALE  FINC
##  4    Salary    double     37       0      37   53788.26  94494.58 ... 56508.32  57562.36
##  5    JobSat character     35       2       3   med  low  low ... high  low  high
##  6      Plan   integer     37       0       3   1  1  3 ... 2  2  1
##  7       Pre   integer     37       0      27   82  62  96 ... 83  59  80
##  8      Post   integer     37       0      22   92  74  97 ... 90  71  87
## ------------------------------------------------------------------------------------------
BarChart(Dept, fill=getColors(c=90, l=45))

## >>> Suggestions
## BarChart(Dept, horiz=TRUE)  # horizontal bar chart
## BarChart(Dept, fill="greens")  # sequential green bars
## PieChart(Dept)  # doughnut (ring) chart
## Plot(Dept)  # bubble plot
## Plot(Dept, stat="count")  # lollipop plot 
## 
## 
## --- Dept ---
## 
## 
## Missing Values of Dept: 1 
## 
## 
##                 ACCT   ADMN   FINC   MKTG   SALE    Total 
## Frequencies:       5      6      4      6     15       36 
## Proportions:   0.139  0.167  0.111  0.167  0.417    1.000 
## 
## 
## Chi-squared test of null hypothesis of equal probabilities 
##   Chisq = 10.944, df = 4, p-value = 0.027

Manual Specification of Colors

Individually specify colors.

getColors(c("black", "blue", "red"))

Generate a custom sequential range of colors.

getColors(pal="aliceblue", end_pal="blue")

style()

The style() function specifies broad color themes, as well as individual characteristics of a visualization. Changes are persistent across subsequent visualizations unless again modified.

style("darkred")
BarChart(Dept)

## >>> Suggestions
## BarChart(Dept, horiz=TRUE)  # horizontal bar chart
## BarChart(Dept, fill="greens")  # sequential green bars
## PieChart(Dept)  # doughnut (ring) chart
## Plot(Dept)  # bubble plot
## Plot(Dept, stat="count")  # lollipop plot 
## 
## 
## --- Dept ---
## 
## 
## Missing Values of Dept: 1 
## 
## 
##                 ACCT   ADMN   FINC   MKTG   SALE    Total 
## Frequencies:       5      6      4      6     15       36 
## Proportions:   0.139  0.167  0.111  0.167  0.417    1.000 
## 
## 
## Chi-squared test of null hypothesis of equal probabilities 
##   Chisq = 10.944, df = 4, p-value = 0.027

Return to the default colors for the theme parameter by either explicitly specifying, or just go with no specification.

style()
## theme set to "colors"

Individual characteristics of a visualization can also be specified. Here change the background color of the visualization window.

style(window_fill="aliceblue")
BarChart(Dept)

## >>> Suggestions
## BarChart(Dept, horiz=TRUE)  # horizontal bar chart
## BarChart(Dept, fill="greens")  # sequential green bars
## PieChart(Dept)  # doughnut (ring) chart
## Plot(Dept)  # bubble plot
## Plot(Dept, stat="count")  # lollipop plot 
## 
## 
## --- Dept ---
## 
## 
## Missing Values of Dept: 1 
## 
## 
##                 ACCT   ADMN   FINC   MKTG   SALE    Total 
## Frequencies:       5      6      4      6     15       36 
## Proportions:   0.139  0.167  0.111  0.167  0.417    1.000 
## 
## 
## Chi-squared test of null hypothesis of equal probabilities 
##   Chisq = 10.944, df = 4, p-value = 0.027

View all modifiable individual characteristics with the show parameter, set to TRUE.

style(show=TRUE)
## 
## Available Themes
## ----------------
## colors lightbronze dodgerblue darkred gray gold darkgreen blue red rose green purple sienna brown orange white light 
## 
## Available Sub-themes
## --------------------
## default black wsj 
## 
## THEME
## theme ........ Theme color ....... colors 
## sub_theme .... Sub-theme style ... default 
## 
## BACKGROUND
## window_fill .. Window fill color ......... aliceblue 
## panel_fill ... Panel fill color .......... white 
## panel_color .. Panel border color .......  gray60 
## panel_lwd .... Panel border line width ..  1.0 
## panel_lty .... Panel border line type ...  solid 
## 
## DATA OBJECTS
## bar_fill ......... Bar fill color ............ 45 139 195 255 
## trans_bar_fill ... Bar fill transparency ..... 0.00 
## bar_color ........ Bar border color .......... 126 144 168 255 
## values ........... Form of bar or pie values . % 
## values_color ..... Color of bar or pie values . white 
## values_cex ....... Size of values on bars, pie  NULL 
## values_digits .... Decimal digits on bars, pie  NULL 
## values_position ....... Position of values ...... .. in 
## 
## pt_fill .......... Point fill color .......... 70 80 90 255 
## trans_pt_fill .... Point fill transparency ..  0.00 
## pt_color ......... Point border color .......  70 80 90 255 
## out_fill ......... Outlier point fill .......  firebrick4 
## out_color ........ Outlier point color ......  firebrick4 
## out2_fill ........ Extreme outlier point fill  firebrick2 
## out2_color ....... Extreme outlier point color firebrick2 
## violin_fill ...... Violin fill color ......... 116 133 151 90 
## violin_color ..... Violin border color ....... gray15 
## box_fill ......... Boxplot fill color ........ 45 139 195 255 
## box_color ........ Boxplot border color ...... gray15 
## fit_color ........ Fit line_color ...........  darkblue 
## se_fill .......... Stnd error fill color ....  26 26 26 25 
## ellipse_fill ..... Ellipse fill color .......  0 0 138 30 
## ellipse_color .... Ellipse border color .....  gray20 
## ellipse_lwd ...... Ellipse border width .....  1.00 
## bubble_text_color  Bubble text color ......... 247 242 230 255 
## segment_color .... Line segment color ........ gray40 
## heat ............. Heat map color ............ gray30 
## 
## AXES
## axis_color ..... Color of axes .............. gray15 
## axis_x_color ... Color of x-axis ............ NULL 
## axis_y_color ... Color of y-axis ............ NULL 
## axis_lwd ....... Axis line width ............ 1.0 
## axis_x_lwd ..... Axis line width ............ NULL 
## axis_y_lwd ..... Axis line width ............ NULL 
## axis_lty ....... Line type of axes .......... solid 
## axis_x_lty ..... Line type of x-axis ........ NULL 
## axis_y_lty ..... Line type of y-axis ........ NULL 
## axis_cex ....... x and y axis text size ........... 0.75 
## axis_x_cex ..... x-axis text size ................. NULL 
## axis_y_cex ..... y-axis text size ................. NULL 
## axis_text_color  x and y axis values text color ... gray20 
## axis_x_text_color  x-axis values text color ....... NULL 
## axis_y_text_color  y-axis values text color ....... NULL 
## rotate_x ....... Rotation of x axis text .......... 0.00 
## rotate_y ....... Rotation of y axis text .......... 0.00 
## offset ......... Offset of values text from axis .. 0.50 
## 
## LABELS
## lab_color ...... Color of axis labels ............. gray15 
## lab_x_color .... Color of x-axis label ............ NULL 
## lab_y_color .... Color of y-axis label ............ NULL 
## lab_cex ........ Size of axis labels .............. 0.95 
## lab_x_cex ...... Size of x-axis labels ............ NULL 
## lab_y_cex ...... Size of y-axis labels ............ NULL 
## main_color ..... Color of plot label .............. gray15 
## main_cex ....... Size of plot title ............... 1.00 
## 
## GRID LINES
## grid_color .... Grid color ...................... 222 217 205 255 
## grid_x_color .. Grid color, vertical ............ NULL 
## grid_y_color .. Grid color, horizontal .......... NULL 
## grid_lwd ...... Grid line width ................. 0.5 
## grid_x_lwd .... Grid line width, vertical ....... NULL 
## grid_y_lwd .... Grid line width, horizontal ..... NULL 
## grid_lty ...... Grid line type .................. solid 
## grid_x_lty .... Grid line type, vertical ........ NULL 
## grid_y_lty .... Grid line type, horizontal ...... NULL 
## 
## TRELLIS STRIP
## strip_fill ...... Trellis strip fill color ..... 127 127 127 55 
## strip_color ..... Trellis strip border color ... gray55 
## strip_text_color  Trellis strip text color ..... gray15 
## 
## ANNOTATION
## add_fill  .. Fill color of annotated figures .. gray20 
## add_trans .. Fill transparency ................ 0 
## add_color .. Color of annotated lines ......... gray30 
## add_cex  ... Size of annotated text ........... 0.75 
## add_lwd  ... Line width of annotated lines .... 0.5 
## add_lty  ... Line type of annotated lines ..... solid 
## 
## NON-GRAPHICAL
## quiet ..... Suppress console output for many functions .. FALSE 
## brief ..... Reduce console output for many functions .... FALSE 
## suggest ... Suggestions for enhanced input .............. TRUE 
## note ... Notes for enhanced input .............. TRUE 
## width ..... Column width ................................ 120 
## n_cat ..... Largest number of unique, equally spaced
##             integer values of a variable for which the
##             variable will be analyzed as categorical .... 1

Full Manual

Use the base R help() function to view the full manual for getColors() or style(). Simply enter a question mark followed by the name of the function.

?getColors
?style