blob: a30e7d0b1a6ddc5018f48da5ffa59ca53c3105ea [file] [log] [blame]
#' IDS Theme for ggplot2
#'
#' Based on Highcharts ggtheme \link[ggthemes]{theme_hc}
#' which again is based on the plots in \url{Highcharts JS}.
#'
#' @note
#'
#' Note that here, unlike with the highcharter theme, you have to set the scale
#' explicitly.
#'
#'
#' @references
#'
#' \link[ggthemes]{theme_hc}
#'
#' \url{http://www.highcharts.com/demo/line-basic}
#'
#' \url{https://github.com/highslide-software/highcharts.com/tree/master/js/themes}
#'
#' @inheritParams ggplot2::theme_bw
#' @param style \code{'light'}, \code{'dark'}.
#' @param bgcolor Deprecated
#' @example inst/examples/ex-ggplot.R
#' @family themes ids
#' @importFrom ggplot2 theme element_rect element_text element_line element_blank
#' @export
theme_ids <- function(base_size = 12,
base_family = idsBaseFontFamily,
style = c("default", "light", "dark"),
bgcolor = NULL) {
if (!is.null(bgcolor)) {
warning("`bgcolor` is deprecated. Use `style` instead.")
style <- bgcolor
}
style <- match.arg(style)
bgcolor <- switch(style,
default = backgroundColor,
"light" = backgroundColor,
"mono" = backgroundColor,
"dark" = backgroundColorDark)
ret <- theme(rect = element_rect(fill = bgcolor, linetype = 0, colour = NA),
text = element_text(size = base_size, family = base_family),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5, size = 13, colour = mediumContrastColor),
title = element_text(hjust = 0.5),
axis.text = element_text(size = 11, family = base_family),
axis.title = element_text(size = 11, family = base_family),
legend.text = element_text(size = 11, family = base_family),
strip.text = element_text(size = 11, family = base_family),
axis.title.x = element_text(hjust = 0.5, size = 11,
colour = mediumContrastColor),
axis.title.y = element_text(hjust = 0.5, size = 11,
margin = margin(r = 10),
colour = mediumContrastColor),
legend.title = element_text(size=11, colour = mediumContrastColor),
panel.grid.major.x = element_line(linetype = "dotted", colour = lowContrastColor),
panel.grid.major.y = element_line(colour = lowContrastColor),
panel.grid.minor.y = element_blank(),
panel.grid.minor.x = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
legend.position = "right",
legend.key = element_rect(fill = paste0(bgcolor,"00")))
if (style == "dark") {
ret <- (ret + theme(rect = element_rect(fill = bgcolor),
text = element_text(colour = textColorDark),
plot.title = element_text(colour = highContrastColorDark),
plot.subtitle = element_text(colour = mediumContrastColorDark),
axis.title.x = element_text(colour = textColorDark),
axis.title.y = element_text(colour = textColorDark),
axis.text.x = element_text(color=textColorDark),
axis.text.y = element_text(color=textColorDark),
panel.grid.major.y = element_line(colour = lowContrastColorDark),
legend.title = element_text(colour = textColorDark)))
}
ret
}
#' IDS color and fill scales
#'
#' Colour and fill scales which use the palettes in
#' \code{\link{ids_pal}()} and are meant for use with
#' \code{\link{theme_ids}()}.
#'
#' @param palette A palette function that when called with a single integer
#' argument (the number of levels in the scale) returns the values that they should take.
#'
#' @importFrom ggthemes gdocs_pal
#' @importFrom ggplot2 discrete_scale
#'
#' @inheritDotParams ggthemes::scale_colour_gdocs
#' @family colour ids
#' @rdname scale_ids
#' @export
scale_colour_ids <- function(palette = "default", ...) {
discrete_scale("colour", "ids", ids_pal(palette=palette, ...))
}
#' @rdname scale_ids
#' @inheritDotParams ggthemes::scale_colour_gdocs
#' @importFrom ggplot2 discrete_scale
#' @export
scale_color_ids <- scale_colour_ids
#' @rdname scale_ids
#' @inheritParams ggthemes::scale_fill_gdocs
#' @importFrom ggplot2 discrete_scale
#' @export
scale_fill_ids <- function(palette = "default", ...) {
discrete_scale("fill", "ids", ids_pal(palette=palette, ...))
}