-
Notifications
You must be signed in to change notification settings - Fork 9
/
README.Rmd
137 lines (106 loc) · 3.75 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# ggdark
[![Travis-CI Build Status](https://travis-ci.org/nsgrantham/ggdark.svg?branch=master)](https://travis-ci.org/nsgrantham/ggdark)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/nsgrantham/ggdark?branch=master&svg=true)](https://ci.appveyor.com/project/nsgrantham/ggdark)
## Installation
You can install ggdark from CRAN with:
```{r cran-installation, eval = FALSE}
install.packages("ggdark")
```
If you want the development version, you can install ggdark from GitHub with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("nsgrantham/ggdark")
```
## Dark mode for ggplot2
```{r gray, fig.path="man/figures/"}
library(ggplot2)
p <- ggplot(diamonds) +
geom_point(aes(carat, price, color = cut)) +
scale_y_continuous(label = scales::dollar) +
guides(color = guide_legend(reverse = TRUE)) +
labs(title = "Prices of 50,000 round cut diamonds by carat and cut",
x = "Weight (carats)",
y = "Price in US dollars",
color = "Quality of the cut")
p + theme_gray() # ggplot default
```
```{r dark-gray, fig.path="man/figures/"}
library(ggdark)
p + dark_theme_gray() # the dark version
```
```{r add-element, fig.path="man/figures/"}
# modify the theme to your liking, as you would in ggplot2
p + dark_theme_gray(base_family = "Fira Sans Condensed Light", base_size = 14) +
theme(plot.title = element_text(family = "Fira Sans Condensed"),
plot.background = element_rect(fill = "grey10"),
panel.background = element_blank(),
panel.grid.major = element_line(color = "grey30", size = 0.2),
panel.grid.minor = element_line(color = "grey30", size = 0.2),
legend.background = element_blank(),
axis.ticks = element_blank(),
legend.key = element_blank(),
legend.position = c(0.815, 0.27))
```
## Dark themes
ggdark provides dark versions of all themes available in ggplot2:
```{r mtcars, fig.path="man/figures/"}
mtcars2 <- within(mtcars, {
vs <- factor(vs, labels = c("V-shaped", "Straight"))
am <- factor(am, labels = c("Automatic", "Manual"))
cyl <- factor(cyl)
gear <- factor(gear)
})
p <- ggplot(mtcars2) +
geom_point(aes(wt, mpg, color = gear)) +
facet_grid(vs ~ am) +
labs(title = "Fuel economy declines as weight increases",
subtitle = "(1973-74)",
caption = "Data from the 1974 Motor Trend US magazine.",
x = "Weight (1000 lbs)",
y = "Fuel economy (mpg)",
color = "Gears")
```
```{r all-themes, fig.path="man/figures/"}
p + dark_theme_gray()
p + dark_theme_bw()
p + dark_theme_linedraw()
p + dark_theme_light() # quite dark
p + dark_theme_dark() # quite light
p + dark_theme_minimal()
p + dark_theme_classic()
p + dark_theme_void()
```
## Make your own dark theme
Use`dark_mode` on any theme to create its dark version.
```{r gapminder, fig.path="man/figures/"}
invert_geom_defaults() # change geom defaults back to black
library(gapminder)
p <- ggplot(subset(gapminder, continent != "Oceania")) +
geom_line(aes(year, lifeExp, group = country, color = country), lwd = 1, show.legend = FALSE) +
facet_wrap(~ continent) +
scale_color_manual(values = country_colors) +
labs(title = "Life expectancy has increased worldwide")
```
```{r fivethirtyeight, fig.path="man/figures/"}
# install.packages("ggthemes")
library(ggthemes)
p + theme_fivethirtyeight()
```
```{r dark-fivethirtyeight, fig.path="man/figures/"}
p + dark_mode(theme_fivethirtyeight())
```
```{r reset-defaults}
invert_geom_defaults() # leave the geom defaults how you found them!
```
Happy plotting! 🖤