scale_brand | R Documentation |
ggplot2
scale_*_brand_*()
functions provide color scales for
ggplot2 based on brand colors defined
in the _brand.yml
file. These functions create discrete, continuous, or
binned scales with sequential, diverging, or qualitative color palettes
that match your brand identity.
scale_brand(
aesthetics = "color",
scale_type = "c",
color_type = "seq",
alpha = NULL,
direction = 1,
na.value = NA,
reverse = FALSE,
...
)
scale_color_brand_d(
aesthetics = "color",
scale_type = "d",
color_type = "qual",
alpha = NULL,
direction = 1,
na.value = NA,
reverse = FALSE,
...
)
scale_color_brand_c(
aesthetics = "color",
scale_type = "c",
color_type = "seq",
alpha = NULL,
direction = 1,
na.value = NA,
reverse = FALSE,
...
)
scale_color_brand_b(
aesthetics = "color",
scale_type = "b",
color_type = "seq",
alpha = NULL,
direction = 1,
na.value = NA,
reverse = FALSE,
...
)
scale_colour_brand_d(
aesthetics = "color",
scale_type = "d",
color_type = "qual",
alpha = NULL,
direction = 1,
na.value = NA,
reverse = FALSE,
...
)
scale_colour_brand_c(
aesthetics = "color",
scale_type = "c",
color_type = "seq",
alpha = NULL,
direction = 1,
na.value = NA,
reverse = FALSE,
...
)
scale_colour_brand_b(
aesthetics = "color",
scale_type = "b",
color_type = "seq",
alpha = NULL,
direction = 1,
na.value = NA,
reverse = FALSE,
...
)
scale_fill_brand_d(
aesthetics = "fill",
scale_type = "d",
color_type = "qual",
alpha = NULL,
direction = 1,
na.value = NA,
reverse = FALSE,
...
)
scale_fill_brand_c(
aesthetics = "fill",
scale_type = "c",
color_type = "seq",
alpha = NULL,
direction = 1,
na.value = NA,
reverse = FALSE,
...
)
scale_fill_brand_b(
aesthetics = "fill",
scale_type = "b",
color_type = "seq",
alpha = NULL,
direction = 1,
na.value = NA,
reverse = FALSE,
...
)
aesthetics |
(Optional) A |
scale_type |
(Optional) A |
color_type |
(Optional) A |
alpha |
(Optional) A number between |
direction |
(Optional) A number ( |
na.value |
(Optional) A |
reverse |
(Optional) A |
... |
Additional arguments passed to the |
_brand.yml
brandr
will always look for a _brand.yml
file in the root directory of
your project. If the file is not found, an error message will be displayed.
You can also set the path to the file manually using the
options()
function:
options(BRANDR_BRAND_YML = "PATH_TO_BRAND.YML")
To control the colors for each brand color scale, assign the desired
hexadecimal color codes in a
character
vector to the following options:
BRANDR_COLOR_SEQUENTIAL
: For sequential color scales
BRANDR_COLOR_DIVERGING
: For diverging color scales
BRANDR_COLOR_QUALITATIVE
: For qualitative color scales
You can use get_brand_color()
to get the hexadecimal
color codes from the _brand.yml
file.
Example:
options( BRANDR_COLOR_SEQUENTIAL = get_brand_color(c("primary", "secondary")), BRANDR_COLOR_DIVERGING = get_brand_color(c("primary", "white", "secondary")), BRANDR_COLOR_QUALITATIVE = get_brand_color(c("primary", "secondary", "tertiary")) )
A ggplot2
scale object.
if (requireNamespace(
c("palmerpenguins", "tidyr", "ggplot2"),
quiet = TRUE
)
) {
library(ggplot2)
library(palmerpenguins)
library(tidyr)
penguins |>
drop_na(bill_length_mm, species) |>
ggplot(aes(x = species, y = bill_length_mm, fill = species)) +
geom_boxplot(outlier.color = get_brand_color("red")) +
geom_jitter(width = 0.2, alpha = 0.1) +
scale_fill_brand_d(alpha = 0.5) +
labs(
x = "Species",
y = "Bill Length (mm)",
fill = "Species"
) +
theme_bw()
}
if (requireNamespace(
c("palmerpenguins", "tidyr", "ggplot2"),
quiet = TRUE
)
) {
library(ggplot2)
library(palmerpenguins)
library(tidyr)
penguins |>
drop_na(flipper_length_mm, species) |>
ggplot(aes(x = flipper_length_mm, fill = species)) +
geom_histogram(alpha = 0.5, bins = 30, position = "identity") +
scale_fill_brand_d() +
labs(
x = "Flipper Length (mm)",
y = "Frequency",
fill = "Species"
) +
theme_bw()
}
if (requireNamespace(
c("palmerpenguins", "tidyr", "ggplot2"),
quiet = TRUE
)
) {
library(ggplot2)
library(palmerpenguins)
library(tidyr)
penguins |>
drop_na(flipper_length_mm, body_mass_g, species) |>
ggplot(
aes(
x = flipper_length_mm,
y = body_mass_g,
color = species,
shape = species
)
) +
geom_point(size = 2) +
geom_smooth(method = "lm", formula = y ~ x, se = FALSE) +
scale_color_brand_d() +
labs(
x = "Flipper Length (mm)",
y = "Body Mass (g)",
color = "Species",
shape = "Species"
) +
theme_bw()
}
if (requireNamespace("ggplot2", quiet = TRUE)) {
library(ggplot2)
faithfuld |>
ggplot(aes(waiting, eruptions, fill = density)) +
geom_raster() +
scale_fill_brand_b() +
labs(
x = "Waiting Time to Next Eruption (min)",
y = "Eruption Time (min)",
fill = "Density"
) +
theme_bw()
}
if (requireNamespace("ggplot2", quiet = TRUE)) {
library(ggplot2)
library(hexbin)
data.frame(x = runif(10000), y = runif(10000)) |>
ggplot(aes(x, y)) +
geom_hex() +
coord_fixed() +
scale_fill_brand_c() +
labs(fill = "") +
theme_bw()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.