#' Ghent University Faculty of Health Sciences Color Palettes
#'
#' Color palette inspired by the Ghent University style guide
#' <\href{https://styleguide.ugent.be/}{https://styleguide.ugent.be/}>
#'
#' @param palette Palette type.
#' Currently there is one available option: \code{"default"}
#' (10-color palette inspired by \emph{Science}).
#' @param alpha Transparency level, a real number in (0, 1].
#' See \code{alpha} in \code{\link[grDevices]{rgb}} for details.
#'
#' @export pal_ugent_ge
#'
#' @importFrom grDevices col2rgb rgb
#' @importFrom scales manual_pal
#'
#' @author Robby De Pauw <\email{robby.depauw@@ugent.be}>
#'
#' @examples
#' library("scales")
#' show_col(pal_ugent_ge("default")(10))
#' show_col(pal_ugent_ge("default", alpha = 0.6)(10))
pal_ugent_ge <- function(palette = c("default"), alpha = 1) {
palette <- match.arg(palette)
if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]")
raw_cols <- ggugent_db$"ge"[[palette]]
raw_cols_rgb <- col2rgb(raw_cols)
alpha_cols <- rgb(
raw_cols_rgb[1L, ], raw_cols_rgb[2L, ], raw_cols_rgb[3L, ],
alpha = alpha * 255L, names = names(raw_cols),
maxColorValue = 255L
)
manual_pal(unname(alpha_cols))
}
#' Primary UGENT Color Scales
#'
#' See \code{\link{pal_ugent_ge}} for details.
#'
#' @inheritParams pal_ugent_ge
#' @param ... additional parameters for \code{\link[ggplot2]{discrete_scale}}
#'
#' @export scale_color_ugent_ge
#'
#' @importFrom ggplot2 discrete_scale
#'
#' @rdname scale_ugent_ge
#'
#' @examples
#' library("ggplot2")
#' data("diamonds")
#'
#' ggplot(
#' subset(diamonds, carat >= 2.2),
#' aes(x = table, y = price, colour = cut)
#' ) +
#' geom_point(alpha = 0.7) +
#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) +
#' theme_bw() +
#' scale_color_ugent_ge()
#'
#' ggplot(
#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70),
#' aes(x = depth, fill = cut)
#' ) +
#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") +
#' theme_bw() +
#' scale_fill_ugent_ge()
scale_color_ugent_ge <- function(palette = c("default"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("colour", "default", pal_ugent_ge(palette, alpha), ...)
}
#' @export scale_colour_ugent_ge
#' @rdname scale_ugent_ge
scale_colour_ugent_ge <- scale_color_ugent_ge
#' @export scale_fill_ugent_ge
#' @importFrom ggplot2 discrete_scale
#' @rdname scale_ugent_ge
scale_fill_ugent_ge <- function(palette = c("default"), alpha = 1, ...) {
palette <- match.arg(palette)
discrete_scale("fill", "default", pal_ugent_ge(palette, alpha), ...)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.