-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
141 lines (120 loc) · 3.08 KB
/
README.Rmd
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
# gghighcontrast
A high contrast retro theme with solid colors.
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
## Installation
This library is currently only available from GitHub. You can install `gghighcontrast` from GitHub with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("topfunky/gghighcontrast")
```
## Usage
A line chart.
```{r line-default, dpi=360, fig.path="man/figures/"}
library(ggplot2)
library(gghighcontrast)
data <- data.frame(
year = c(
1979,
1979,
1980,
1980,
1981,
1981,
1982,
1982,
1979,
1980,
1981,
1982
),
product = c("A", "B", "A", "B", "A", "B", "A", "B", "C", "C", "C", "C"),
revenue = c(10, 21, 12, 11, 13, 15, 16, 18, 5, 8, 3, 19)
)
plot_line_high_contrast <-
function(data,
foreground_color = "white",
background_color = "black") {
chart <-
ggplot(data,
aes(
x = year,
y = revenue,
group = product,
linetype = product
)) +
geom_line(color = foreground_color, size = 1) +
theme_high_contrast(
foreground_color = foreground_color,
background_color = background_color,
base_family = "InputMono"
) +
theme(legend.position = "none") +
scale_linetype_high_contrast() +
labs(title = "CRT Sales, 1979-1982",
subtitle = "Non-GAAP, worldwide",
caption = "Data from example.com")
}
p <- plot_line_high_contrast(data)
p
```
A bar chart.
```{r bar-default, dpi=360, fig.path="man/figures/"}
library(ggplot2)
library(gghighcontrast)
data <- data.frame(
year = c(
1979,
1979,
1980,
1980,
1981,
1981,
1982,
1982,
1979,
1980,
1981,
1982
),
product = c("A", "B", "A", "B", "A", "B", "A", "B", "C", "C", "C", "C"),
revenue = c(10, 21, 12, 11, 13, 15, 16, 18, 5, 8, 3, 19)
)
plot_bar_high_contrast <-
function(data,
foreground_color = "white",
background_color = "black") {
chart <- ggplot(data, aes(x = year, y = revenue, fill = product)) +
geom_bar(stat = "identity", position = position_dodge()) +
geom_hline(yintercept = 0,
color = foreground_color,
size = 1) +
theme_high_contrast(
base_family = "InputMono",
foreground_color = foreground_color,
background_color = background_color
) +
scale_fill_high_contrast(foreground_color = foreground_color) +
labs(title = "CRT Sales, 1979-1982",
subtitle = "Non-GAAP, worldwide",
caption = "Data from example.com")
}
p <- plot_bar_high_contrast(data)
p
```
For fun, try other foreground and background colors such as:
```{r eval=FALSE}
dayglo_orange = "#ff6700"
neon_green = "#00ff00"
```
## Usage
Download the [Input Mono font](https://input.fontbureau.com/) to achieve the styles you see here.