-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgraphing.R
176 lines (171 loc) · 6.1 KB
/
graphing.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#' Minimal ggplot2 theme using the Roboto Condensed and Roboto Bold fonts
#'
#' @param base_size base font size
#' @param strip_text_size,strip_text_margin plot strip text size and margin
#' @param subtitle_size,subtitle_margin plot subtitle size and margin
#' @param plot_title_size,plot_title_margin plot title size and margin
#' @param ... Other arguments passed to \code{theme_minimal}
#'
#' @details The Roboto Condensed and Roboto Bold fonts are both Google fonts;
#' they can be found at \url{https://fonts.google.com/specimen/Roboto+Condensed}
#' and \url{https://fonts.google.com/specimen/Roboto}. These fonts must be
#' installed locally on your computer for this theme to work.
#'
#' @examples
#' \dontrun{
#' library(ggplot2)
#'
#' ggplot(mtcars, aes(wt, mpg)) +
#' geom_point() +
#' labs(title = "A Lovely Plot",
#' subtitle = "What can the subtitle tell us?") +
#' theme_roboto()
#'}
#'
#' @export
theme_roboto <- function(base_size = 11,
strip_text_size = 12,
strip_text_margin = 5,
subtitle_size = 13,
subtitle_margin = 10,
plot_title_size = 16,
plot_title_margin = 10,
...) {
ret <- ggplot2::theme_minimal(base_family = "RobotoCondensed-Regular",
base_size = base_size, ...)
ret$strip.text <- ggplot2::element_text(
hjust = 0, size = strip_text_size,
margin = ggplot2::margin(b = strip_text_margin),
family = "Roboto-Bold"
)
ret$plot.subtitle <- ggplot2::element_text(
hjust = 0, size = subtitle_size,
margin = ggplot2::margin(b = subtitle_margin),
family = "RobotoCondensed-Regular"
)
ret$plot.title <- ggplot2::element_text(
hjust = 0, size = plot_title_size,
margin = ggplot2::margin(b = plot_title_margin),
family = "Roboto-Bold"
)
ret
}
#' Minimal ggplot2 theme using the IBM Plex Sans fonts
#'
#' @param base_size base font size
#' @param strip_text_size,strip_text_margin plot strip text size and margin
#' @param subtitle_size,subtitle_margin plot subtitle size and margin
#' @param plot_title_size,plot_title_margin plot title size and margin
#' @param ... Other arguments passed to \code{theme_minimal}
#'
#' @details The IBM Plex fonts are open source and can be found at
#' \url{https://ibm.github.io/type/}. These fonts must be installed locally on
#' your computer for this theme to work.
#'
#' @examples
#' \dontrun{
#' library(ggplot2)
#'
#' ggplot(mtcars, aes(wt, mpg)) +
#' geom_point() +
#' labs(title = "A Lovely Plot",
#' subtitle = "What can the subtitle tell us?") +
#' theme_plex()
#'
#' ggplot(diamonds, aes(carat, price, color = clarity)) +
#' geom_point(alpha = 0.7) +
#' facet_wrap(~cut) +
#' labs(title = "A Lovely Plot",
#' subtitle = "What can the subtitle tell us?") +
#' theme_plex()
#'
#'}
#'
#' @export
theme_plex <- function(base_size = 11,
strip_text_size = 12,
strip_text_margin = 5,
subtitle_size = 13,
subtitle_margin = 10,
plot_title_size = 16,
plot_title_margin = 10,
...) {
ret <- ggplot2::theme_minimal(base_family = "IBMPlexSans",
base_size = base_size, ...)
ret$strip.text <- ggplot2::element_text(
hjust = 0, size = strip_text_size,
margin = ggplot2::margin(b = strip_text_margin),
family = "IBMPlexSans-Medium"
)
ret$plot.subtitle <- ggplot2::element_text(
hjust = 0, size = subtitle_size,
margin = ggplot2::margin(b = subtitle_margin),
family = "IBMPlexSans"
)
ret$plot.title <- ggplot2::element_text(
hjust = 0, size = plot_title_size,
margin = ggplot2::margin(b = plot_title_margin),
family = "IBMPlexSans-Bold"
)
ret
}
#' Light ggplot2 theme using the IBM Plex Sans fonts
#'
#' @param base_size base font size
#' @param strip_text_size,strip_text_margin plot strip text size and margin
#' @param subtitle_size,subtitle_margin plot subtitle size and margin
#' @param plot_title_size,plot_title_margin plot title size and margin
#' @param ... Other arguments passed to \code{theme_light}
#'
#' @details The IBM Plex fonts are open source and can be found at
#' \url{https://ibm.github.io/type/}. These fonts must be installed locally on
#' your computer for this theme to work.
#'
#' @examples
#' \dontrun{
#' library(ggplot2)
#'
#' ggplot(mtcars, aes(wt, mpg)) +
#' geom_point() +
#' labs(title = "A Lovely Plot",
#' subtitle = "What can the subtitle tell us?") +
#' theme_light_plex()
#'
#' ggplot(diamonds, aes(carat, price, color = clarity)) +
#' geom_point(alpha = 0.7) +
#' facet_wrap(~cut) +
#' labs(title = "A Lovely Plot",
#' subtitle = "What can the subtitle tell us?") +
#' theme_light_plex()
#'
#'}
#'
#' @export
theme_light_plex <- function(base_size = 11,
strip_text_size = 12,
strip_text_margin = 5,
subtitle_size = 13,
subtitle_margin = 10,
plot_title_size = 16,
plot_title_margin = 10,
...) {
ret <- ggplot2::theme_light(base_family = "IBMPlexSans",
base_size = base_size, ...)
ret$strip.text <- ggplot2::element_text(
colour = "white",
size = strip_text_size,
margin = ggplot2::margin(b = strip_text_margin, t = strip_text_margin),
family = "IBMPlexSans-Medium"
)
ret$plot.subtitle <- ggplot2::element_text(
hjust = 0, size = subtitle_size,
margin = ggplot2::margin(b = subtitle_margin),
family = "IBMPlexSans"
)
ret$plot.title <- ggplot2::element_text(
hjust = 0, size = plot_title_size,
margin = ggplot2::margin(b = plot_title_margin),
family = "IBMPlexSans-Bold"
)
ret
}