Debian Codegraph @

man/scale_colour_continuous_diverging.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/scale_diverging.R
3 \name{scale_colour_continuous_diverging}
4 \alias{scale_colour_continuous_diverging}
5 \alias{scale_color_continuous_diverging}
6 \alias{scale_fill_continuous_diverging}
7 \title{HCL-Based Continuous Diverging Color Scales for ggplot2}
8 \usage{
9 scale_colour_continuous_diverging(
10 palette = NULL,
11 c1 = NULL,
12 cmax = NULL,
13 l1 = NULL,
14 l2 = NULL,
15 h1 = NULL,
16 h2 = NULL,
17 p1 = NULL,
18 p2 = NULL,
19 alpha = 1,
20 rev = FALSE,
21 mid = 0,
22 na.value = "grey50",
23 guide = "colourbar",
24 n_interp = 11,
25 aesthetics = "colour",
26 ...
27 )
28
29 scale_color_continuous_diverging(
30 palette = NULL,
31 c1 = NULL,
32 cmax = NULL,
33 l1 = NULL,
34 l2 = NULL,
35 h1 = NULL,
36 h2 = NULL,
37 p1 = NULL,
38 p2 = NULL,
39 alpha = 1,
40 rev = FALSE,
41 mid = 0,
42 na.value = "grey50",
43 guide = "colourbar",
44 n_interp = 11,
45 aesthetics = "colour",
46 ...
47 )
48
49 scale_fill_continuous_diverging(..., aesthetics = "fill")
50 }
51 \arguments{
52 \item{palette}{The name of the palette to be used. Run \code{hcl_palettes(type = "diverging")} for available options.}
53
54 \item{c1}{Chroma value at the scale endpoints.}
55
56 \item{cmax}{Maximum chroma value.}
57
58 \item{l1}{Luminance value at the scale endpoints.}
59
60 \item{l2}{Luminance value at the scale midpoint.}
61
62 \item{h1}{Hue value at the first endpoint.}
63
64 \item{h2}{Hue value at the second endpoint.}
65
66 \item{p1}{Control parameter determining how chroma should vary (1 = linear, 2 = quadratic, etc.).}
67
68 \item{p2}{Control parameter determining how luminance should vary (1 = linear, 2 = quadratic, etc.).}
69
70 \item{alpha}{Numeric vector of values in the range \code{[0, 1]} for alpha transparency channel (0 means transparent and 1 means opaque).}
71
72 \item{rev}{If \code{TRUE}, reverses the order of the colors in the color scale.}
73
74 \item{mid}{Data value that should be mapped to the mid-point of the diverging color scale.}
75
76 \item{na.value}{Color to be used for missing data points.}
77
78 \item{guide}{Type of legend. Use \code{"colourbar"} for continuous color bar.}
79
80 \item{n_interp}{Number of discrete colors that should be used to interpolate the continuous color scale.
81 It is important to use an odd number to capture the color at the midpoint.}
82
83 \item{aesthetics}{The ggplot2 aesthetics to which this scale should be applied.}
84
85 \item{...}{common continuous scale parameters: `name`, `breaks`, `labels`, and `limits`. See
86 \code{\link[ggplot2]{continuous_scale}} for more details.}
87 }
88 \description{
89 Continuous ggplot2 color scales using the color palettes generated by \code{\link{diverging_hcl}}.
90 }
91 \details{
92 If both a valid palette name and palette parameters are provided then the provided palette parameters overwrite the parameters in the
93 named palette. This enables easy customization of named palettes.
94 }
95 \examples{
96 # adapted from stackoverflow: https://stackoverflow.com/a/20127706/4975218
97
98 library("ggplot2")
99
100 # generate dataset and base plot
101 set.seed(100)
102 df <- data.frame(country = LETTERS, V = runif(26, -40, 40))
103 df$country = factor(LETTERS, LETTERS[order(df$V)]) # reorder factors
104 gg <- ggplot(df, aes(x = country, y = V, fill = V)) +
105 geom_bar(stat = "identity") +
106 labs(y = "Under/over valuation in \%", x = "Country") +
107 coord_flip() + theme_minimal()
108
109 # plot with default diverging scale
110 gg + scale_fill_continuous_diverging()
111
112 # plot with alternative scale
113 gg + scale_fill_continuous_diverging(palette = "Purple-Green")
114
115 # plot with modified alternative scale
116 gg + scale_fill_continuous_diverging(palette = "Blue-Red 3", l1 = 30, l2 = 100, p1 = .9, p2 = 1.2)
117 }