Selection of colors for Likert plots.

Share:

Description

Selection of colors for Likert plots.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ColorSet(nc, ReferenceZero=NULL)
likertColor(nc, ReferenceZero=NULL,
                colorFunction=c("diverge_hcl","sequential_hcl"),
                colorFunctionOption=c("lighter","flatter","default"),
                colorFunctionArgs=
                  likertColorFunctionArgs[[colorFunctionOption, colorFunction]],
                ...)
likertColorBrewer(nc, ReferenceZero=NULL,
                  BrewerPaletteName="RdBu", middle.color="gray90")

brewer.pal.likert(n, name, middle.color)

Arguments

n, nc

Number of colors in the palette. If there are more levels than RColorBrewer normally handles, we automatically interpolate with colorRampPalette.

ReferenceZero

Numeric scalar or NULL. The position in the range
seq(0, attr(x, "nlevels")+.5, .5) where the reference line at 0 will be placed. attr(x, "nlevels") is the number of columns of the original argument x, before it has been coerced to a "likert" object. The default NULL corresponds to the middle level if there are an odd number of levels, and to half-way between the two middle levels if there are an even number of levels. This argument is used when the number of positive levels and the number of negative levels are not the same. For example, with 4 levels
c("Disagee", "Neutral", "Weak Agree", "Strong Agree"), the argument would be specified ReferenceZero=2 indicating that the graphical split would be in the middle of the second group with label "Neutral".

colorFunction

Function name from the colorspace package, either "diverge_hcl" or
"sequential_hcl".

colorFunctionOption

Name of a list item defined inside the likertColor function. The item contains a list of parameters to the function identified in the colorFunction argument.

colorFunctionArgs

list of arguments to the colorspace function. The default selects the values by indexing into a list defined in the likertColor function using the values of the two arguments colorFunction and colorFunctionOption

. For non-default usage, see the BlueOrange example in this help page.

...

Other arguments are ignored.

BrewerPaletteName, name

RColorBrewer palette names. We default to the diverging palette RdBu. Diverging palettes are usually appropriate for two-directional scales (Agree–Disagree). Sequential palettes are often appropriate for one-directional scales (Age Ranges). Qualitative palettes are usually not appropriate for likert plots.

middle.color

Darker middle color than the default "#F7F7F7" in the RdBu scheme.

Details

These are support functions for the plot.likert function. Please see plot.likert for details.

likertColor uses by default the diverge_hcl diverging palette defined by the argument
colorFunctionOption="lighter".

likertColorBrewer by default uses the "RdBu" diverging palette from RColorBrewer.

Value

ColorSet returns a vector of integers, one per each level, corresponding to the strength of the levels from Disagree to Agree. For balanced levels, such as
c("Disagree Strongly", "Disagree Weakly", "Agree Weakly", "Agree Strongly"),
corresponding to nc=4, ReferenceZero=2.5, it returns -2 -1 1 2. For unbalanced levels, such as c("Disagree", "Neutral", "Agree Weakly", "Agree Strongly"), corresponding to nc=4, ReferenceZero=2, it returns -1 0 1 2.

likertColor returns a subset of a palette constructed by either diverge_hcl or sequential_hcl in the colorspace package. The subset corresponds to the levels specified by ColorSet.

brewer.pal.likert returns a RColorBrewer palette.

likertColorBrewer returns a subset of a palette constructed by brewer.pal.likert. The subset corresponds to the levels specified by ColorSet.

Author(s)

Richard M. Heiberger, with contributions from Naomi B. Robbins <naomi@nbr-graphs.com>.

Maintainer: Richard M. Heiberger <rmh@temple.edu>

See Also

plot.likert

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
brewer.pal.likert(4, "RdBu")
brewer.pal.likert(5, "RdBu")
ColorSet(4)
ColorSet(4, 2)
likertColor(4)
likertColor(4, 2.5) ## same as above
likertColor(4, 2)   ## one negative level and two positive levels: default
likertColor(5, 3)[-2] ## one negative level and two positive levels: stronger negative

## Not run: 
  ## Examples illustrating the six predefined likertColor palettes, and how
  ## to define additional hcl color palettes for use with the likert functions.

  data(ProfDiv)
  ProfDiv.df <- data.frame(ProfDiv)

  likert( ~ . , ProfDiv.df, horizontal=FALSE, positive.order=FALSE)
  likert( ~ . , ProfDiv.df, horizontal=FALSE, positive.order=FALSE,
         colorFunctionOption="default")
  likert( ~ . , ProfDiv.df, horizontal=FALSE, positive.order=FALSE,
         colorFunctionOption="flatter")
  likert( ~ . , ProfDiv.df, horizontal=FALSE, positive.order=FALSE,
         colorFunction="sequential_hcl")
  likert( ~ . , ProfDiv.df, horizontal=FALSE, positive.order=FALSE,
         colorFunction="sequential_hcl", colorFunctionOption="default")
  likert( ~ . , ProfDiv.df, horizontal=FALSE, positive.order=FALSE,
         colorFunction="sequential_hcl", colorFunctionOption="flatter")

  likert(ProfDiv, horizontal=FALSE, positive.order=FALSE)
  likert(ProfDiv, horizontal=FALSE, positive.order=FALSE,
         colorFunctionOption="default")
  likert(ProfDiv, horizontal=FALSE, positive.order=FALSE,
         colorFunctionOption="flatter")
  likert(ProfDiv, horizontal=FALSE, positive.order=FALSE,
         colorFunction="sequential_hcl")
  likert(ProfDiv, horizontal=FALSE, positive.order=FALSE,
         colorFunction="sequential_hcl", colorFunctionOption="default")
  likert(ProfDiv, horizontal=FALSE, positive.order=FALSE,
         colorFunction="sequential_hcl", colorFunctionOption="flatter")

  likertMosaic(ProfDiv.df)
  likertMosaic(ProfDiv.df, colorFunctionOption="default")
  likertMosaic(ProfDiv.df, colorFunctionOption="flatter")
  likertMosaic(ProfDiv.df, colorFunction="sequential_hcl")
  likertMosaic(ProfDiv.df, colorFunction="sequential_hcl",
               colorFunctionOption="default")
  likertMosaic(ProfDiv.df, colorFunction="sequential_hcl",
               colorFunctionOption="flatter")

  ## specify an hcl palette for use with the likert functions.
  BlueOrange <- likertColor(nc=4, ReferenceZero=NULL,
                            colorFunction="diverge_hcl",
                            colorFunctionArgs=
                              list(h=c(246, 40), c=96, l=c(65,90), power=1.5))
  likert( ~ . , ProfDiv.df, horizontal=FALSE, positive.order=FALSE, col=BlueOrange)

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.