blob: fb3176bb680ebe2d703facb09ed6b2fd2319f8b9 [file] [log] [blame]
Marc Kupietz52144812020-12-14 23:41:56 +01001#' IDS Theme for ggplot2
2#'
3#' Based on Highcharts ggtheme \link[ggthemes]{theme_hc}
4#' which again is based on the plots in \url{Highcharts JS}.
5#'
6#' @note
7#'
8#' Note that here, unlike with the highcharter theme, you have to set the scale
9#' explicitly.
10#'
11#'
12#' @references
13#'
14#' \link[ggthemes]{theme_hc}
15#'
16#' \url{http://www.highcharts.com/demo/line-basic}
17#'
18#' \url{https://github.com/highslide-software/highcharts.com/tree/master/js/themes}
19#'
20#' @inheritParams ggplot2::theme_bw
21#' @param style \code{'light'}, \code{'dark'}.
22#' @param bgcolor Deprecated
23#' @example inst/examples/ex-ggplot.R
24#' @family themes ids
25#' @importFrom ggplot2 theme element_rect element_text element_line element_blank
26#' @export
27theme_ids <- function(base_size = 14,
28 base_family = idsBaseFontFamily,
29 style = c("default", "light", "dark"),
30 bgcolor = NULL) {
31
32 if (!is.null(bgcolor)) {
33 warning("`bgcolor` is deprecated. Use `style` instead.")
34 style <- bgcolor
35 }
36 style <- match.arg(style)
37 bgcolor <- switch(style,
38 default = backgroundColor,
39 "light" = backgroundColor,
40 "mono" = backgroundColor,
41 "dark" = backgroundColorDark)
42
43 ret <- theme(rect = element_rect(fill = bgcolor, linetype = 0, colour = NA),
44 text = element_text(size = base_size, family = base_family),
45 plot.title = element_text(hjust = 0.5),
46 plot.subtitle = element_text(hjust = 0.5, size = 13, colour = mediumContrastColor),
47 title = element_text(hjust = 0.5),
48 axis.title.x = element_text(hjust = 0.5, size=11),
49 axis.title.y = element_text(hjust = 0.5, size=11),
50 legend.title = element_text(size=11),
51 panel.grid.major.y = element_line(colour = lowContrastColor),
52 panel.grid.minor.y = element_blank(),
53 panel.grid.major.x = element_blank(),
54 panel.grid.minor.x = element_blank(),
55 panel.border = element_blank(),
56 panel.background = element_blank(),
57 legend.position = "right",
58 legend.key = element_rect(fill = paste0(bgcolor,"00")))
59
60 if (style == "dark") {
61 ret <- (ret + theme(rect = element_rect(fill = bgcolor),
62 text = element_text(colour = textColorDark),
63 plot.title = element_text(colour = highContrastColorDark),
64 plot.subtitle = element_text(colour = mediumContrastColorDark),
65 axis.title.x = element_text(colour = textColorDark),
66 axis.title.y = element_text(colour = textColorDark),
67 axis.text.x = element_text(color=textColorDark),
68 axis.text.y = element_text(color=textColorDark),
69 panel.grid.major.y = element_line(colour = lowContrastColorDark),
70 legend.title = element_text(colour = textColorDark)))
71 }
72 ret
73}
74
75
76#' IDS color and fill scales
77#'
78#' Colour and fill scales which use the palettes in
79#' \code{\link{ids_pal}()} and are meant for use with
80#' \code{\link{theme_ids}()}.
81#'
82#' @param palette A palette function that when called with a single integer
83#' argument (the number of levels in the scale) returns the values that they should take.
84#'
85#' @importFrom ggthemes gdocs_pal
86#' @importFrom ggplot2 discrete_scale
87#'
88#' @inheritDotParams ggthemes::scale_colour_gdocs
89#' @family colour ids
90#' @rdname scale_ids
91#' @export
92scale_colour_ids <- function(palette = "default", ...) {
93 discrete_scale("colour", "ids", ids_pal(), ...)
94}
95
96#' @rdname scale_ids
97#' @inheritDotParams ggthemes::scale_colour_gdocs
98#' @importFrom ggplot2 discrete_scale
99#' @export
100scale_color_ids <- scale_colour_ids
101
102#' @rdname scale_ids
103#' @inheritParams ggthemes::scale_fill_gdocs
104#' @importFrom ggplot2 discrete_scale
105#' @export
106scale_fill_ids <- function(palette = "default", ...) {
107 discrete_scale("fill", "ids", ids_pal(), ...)
108}