-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththemes.R
96 lines (85 loc) · 2.53 KB
/
themes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Inspired by: https://drsimonj.svbtle.com/creating-corporate-colour-palettes-for-ggplot2
#' RStudio ggplot2 Theme
#' @import ggplot2
#' @export
theme_rstudio <- function() {
theme_minimal(base_size = 12, base_family = "sans") %+replace%
theme(
plot.title = element_text(size = 14, margin = margin(b = 1, unit = "cm"), hjust = 0),
title = element_text(color = '#585858'),
legend.direction = 'horizontal',
legend.position = 'bottom'
)
}
rstudio_cols <- c(
blue ="#75aadb",
darkblue ="#4c83b6",
lightblue ="#e3eef8",
lightgrey ="#f8f8f8",
superlightgrey ="#e0e0e0",
mediumgrey ="#c8c8c8",
mediumdarkgrey ="#a0a0a0",
darkgrey ="#585858",
orange ="#e6553a",
darkorange ="#d54a30",
brown ="#5d4c45",
darkbrown ="#4d3c35",
lightbrown ="#8d817c",
yellow ="#fcbf49",
darkyellow ="#f9b02d",
green ="#a3c586",
darkgreen ="#789d57"
)
#' Return RStudio Color Values
#'
#' @param ... Pass in the names of the desired colors. To see available color
#' names, run the function with no arguments.
#'
#' @export
get_rstudio_cols <- function(...) {
cols <- c(...)
if (is.null(cols))
return(rstudio_cols)
rstudio_cols[cols]
}
rstudio_pals <- list(
main = get_rstudio_cols('blue', 'green','orange', 'yellow'),
grey = get_rstudio_cols('mediumgrey','mediumdarkgrey', 'darkgrey'),
cool = get_rstudio_cols('lightblue', 'blue', 'mediumdarkgrey', 'darkgrey')
)
get_rstudio_pal <- function(palette = "main", ...) {
pal <- rstudio_pals[[palette]]
grDevices::colorRampPalette(pal, ...)
}
#' RStudio Color Scheme
#'
#' @param palette One of main, grey, or cool
#' @param discrete Whether or not the color aesthetic is discrete or numeric.
#' @param ... Other arguments to \code(discrete_scale) or
#' \code(scale_color_gradient)
#'
#' @export
scale_color_rstudio <- function(palette = "main", discrete = TRUE, ...) {
pal <- get_rstudio_pal(palette)
if (discrete) {
discrete_scale("colour" , paste0('rstudio_', palette), pal, ...)
} else {
scale_color_gradientn(colours = pal(256), ...)
}
}
#' RStudio Fill Scheme
#'
#' @param palette One of main, grey, or cool
#' @param discrete Whether or not the fill aesthetic is discrete or numeric.
#' @param ... Other arguments to \code(discrete_scale) or
#' \code(scale_fill_gradient)
#'
#' @export
scale_fill_rstudio <- function(palette = "main", discrete = TRUE, ...) {
pal <- get_rstudio_pal(palette)
if (discrete) {
discrete_scale("fill" , paste0('rstudio_', palette), pal, ...)
} else {
scale_fill_gradientn(colours = pal(256), ...)
}
}