| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/scale_divergingx.R |
| 3 |
\name{scale_colour_binned_divergingx} |
| 4 |
\alias{scale_colour_binned_divergingx} |
| 5 |
\alias{scale_color_binned_divergingx} |
| 6 |
\alias{scale_fill_binned_divergingx} |
| 7 |
\title{HCL-Based Binned Flexible Diverging Scales for ggplot2} |
| 8 |
\usage{ |
| 9 |
scale_colour_binned_divergingx( |
| 10 |
palette = "Geyser", |
| 11 |
c1 = NULL, |
| 12 |
c2 = NULL, |
| 13 |
c3 = NULL, |
| 14 |
l1 = NULL, |
| 15 |
l2 = NULL, |
| 16 |
l3 = NULL, |
| 17 |
h1 = NULL, |
| 18 |
h2 = NULL, |
| 19 |
h3 = NULL, |
| 20 |
p1 = NULL, |
| 21 |
p2 = NULL, |
| 22 |
p3 = NULL, |
| 23 |
p4 = NULL, |
| 24 |
cmax1 = NULL, |
| 25 |
cmax2 = NULL, |
| 26 |
alpha = 1, |
| 27 |
rev = FALSE, |
| 28 |
mid = 0, |
| 29 |
na.value = "grey50", |
| 30 |
guide = "coloursteps", |
| 31 |
n_interp = 11, |
| 32 |
aesthetics = "colour", |
| 33 |
... |
| 34 |
) |
| 35 |
|
| 36 |
scale_color_binned_divergingx( |
| 37 |
palette = "Geyser", |
| 38 |
c1 = NULL, |
| 39 |
c2 = NULL, |
| 40 |
c3 = NULL, |
| 41 |
l1 = NULL, |
| 42 |
l2 = NULL, |
| 43 |
l3 = NULL, |
| 44 |
h1 = NULL, |
| 45 |
h2 = NULL, |
| 46 |
h3 = NULL, |
| 47 |
p1 = NULL, |
| 48 |
p2 = NULL, |
| 49 |
p3 = NULL, |
| 50 |
p4 = NULL, |
| 51 |
cmax1 = NULL, |
| 52 |
cmax2 = NULL, |
| 53 |
alpha = 1, |
| 54 |
rev = FALSE, |
| 55 |
mid = 0, |
| 56 |
na.value = "grey50", |
| 57 |
guide = "coloursteps", |
| 58 |
n_interp = 11, |
| 59 |
aesthetics = "colour", |
| 60 |
... |
| 61 |
) |
| 62 |
|
| 63 |
scale_fill_binned_divergingx(..., aesthetics = "fill") |
| 64 |
} |
| 65 |
\arguments{ |
| 66 |
\item{palette}{The name of the palette to be used.} |
| 67 |
|
| 68 |
\item{h1, h2, h3, c1, c2, c3, l1, l2, l3, p1, p2, p3, p4, cmax1, cmax2}{Parameters to customize the scale. See \code{\link{divergingx_hcl}} for details.} |
| 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{"coloursteps"} for color bar with discrete steps.} |
| 79 |
|
| 80 |
\item{n_interp}{Number of discrete colors that should be used to interpolate the binned color scale. |
| 81 |
For diverging scales, 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 binned scale parameters: `name`, `breaks`, `labels`, and `limits`. See |
| 86 |
\code{\link[ggplot2]{binned_scale}} for more details.} |
| 87 |
} |
| 88 |
\description{ |
| 89 |
Binned ggplot2 color scales using the color palettes generated by \code{\link{divergingx_hcl}}. |
| 90 |
} |
| 91 |
\details{ |
| 92 |
Available CARTO palettes: ArmyRose, Earth, Fall, Geyser, TealRose, Temps, Tropic. |
| 93 |
|
| 94 |
Available ColorBrewer.org palettes: Spectral, PuOr, RdYlGn, RdYlBu, RdGy, |
| 95 |
BrBG, PiYG, PRGn, RdBu. |
| 96 |
|
| 97 |
If both a valid palette name and palette parameters are provided then the provided palette parameters overwrite the parameters in the |
| 98 |
named palette. This enables easy customization of named palettes. |
| 99 |
} |
| 100 |
\examples{ |
| 101 |
library("ggplot2") |
| 102 |
|
| 103 |
# volcano plot (difference from mean height) |
| 104 |
nx = 87 |
| 105 |
ny = 61 |
| 106 |
df <- data.frame(diff = c(volcano) - mean(volcano), x = rep(1:nx, ny), y = rep(1:ny, each = nx)) |
| 107 |
ggplot(df, aes(x, y, fill=diff)) + |
| 108 |
geom_raster() + scale_fill_binned_divergingx(palette = "Fall", rev = TRUE) + |
| 109 |
coord_fixed(expand = FALSE) |
| 110 |
|
| 111 |
|
| 112 |
# adapted from stackoverflow: https://stackoverflow.com/a/20127706/4975218 |
| 113 |
|
| 114 |
# generate dataset and base plot |
| 115 |
set.seed(100) |
| 116 |
df <- data.frame(country = LETTERS, V = runif(26, -40, 40)) |
| 117 |
df$country = factor(LETTERS, LETTERS[order(df$V)]) # reorder factors |
| 118 |
gg <- ggplot(df, aes(x = country, y = V, fill = V)) + |
| 119 |
geom_bar(stat = "identity") + |
| 120 |
labs(y = "Under/over valuation in \%", x = "Country") + |
| 121 |
coord_flip() + theme_minimal() |
| 122 |
|
| 123 |
# plot with diverging scale "Geyser" |
| 124 |
gg + scale_fill_binned_divergingx(palette = "Geyser", n.breaks = 6) |
| 125 |
} |