likertColor
Selection of colors for Likert plots.
Selection of colors for Likert plots.
- Keywords
- hplot
Usage
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 withcolorRampPalette
.- ReferenceZero
Numeric scalar or
NULL
. The position in the rangeseq(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 argumentx
, before it has been coerced to a"likert"
object. The defaultNULL
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 levelsc("Disagee", "Neutral", "Weak Agree", "Strong Agree")
, the argument would be specifiedReferenceZero=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 thecolorFunction
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 argumentscolorFunction
andcolorFunctionOption
- …
Other arguments are ignored.
- BrewerPaletteName, name
RColorBrewer
palette names. We default to the diverging paletteRdBu
. 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 theRdBu
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
.
See Also
Examples
# NOT RUN {
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)
# }