generated from tschaffter/rstudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sagethemes.Rmd
131 lines (105 loc) · 3.37 KB
/
sagethemes.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
---
title: "Sagethemes"
author: "Sage Bionetworks"
date: "`r Sys.Date()`"
output:
html_document:
df_print: paged
code_fold: show
toc: yes
toc_float: yes
pdf_document:
toc: yes
---
# sagethemes
<!-- badges: start -->
[![R build status](https://github.com/Sage-Bionetworks/sagethemes/workflows/R-CMD-check/badge.svg)](https://github.com/Sage-Bionetworks/sagethemes/actions)
<!-- badges: end -->
The sagethemes package provides plot color palettes and themes that use the Sage
Bionetworks branded colors.
## Installation
```{r install, eval = FALSE}
remotes::install_github("Sage-Bionetworks/sagethemes", ref = "main")
```
## Colors
Colors were developed by the Sage design team and are available in the list
`sage_colors`.
```{r color-list}
library("sagethemes")
head(sage_colors, n = 3)
```
## Usage
sagethemes provides continuous, discrete, and binned scales. It also provides a
default theme, `theme_sage()`, which is currently just `theme_minimal()` but
with Lato as the font family and a larger default font size. Lato must be
installed for this theme to work. See the Fonts section below, and
`?import_lato` for more information.
```{r discrete}
library("ggplot2")
library("extrafont")
library("sagethemes")
# discrete
ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point() +
scale_color_sage_d() +
theme_sage()
ggplot(mpg, aes(x = factor(year), fill = class)) +
geom_bar() +
scale_fill_sage_d() +
theme_sage()
```
```{r continuous}
# continuous
ggplot(faithfuld, aes(waiting, eruptions, fill = density)) +
geom_tile() +
scale_fill_sage_c(option = "powder") +
theme_sage()
```
```{r binned}
# binned -- note this requires ggplot2 version 3.3.1.9000 or greater
ggplot(faithfuld, aes(waiting, eruptions, fill = density)) +
geom_tile() +
scale_fill_sage_b(option = "powder") +
theme_sage()
```
## Fonts
Sage Bionetworks uses [Lato](http://www.latofonts.com/lato-free-fonts/). If
you've installed Lato on your system, you should be able to use it in plots.
However, to output to PDF, PostScript, or bitmap files on Windows, you need to
register the font. sagethemes includes a copy of Lato, and you can load it with
`import_lato()`. If saving to PDF you'll also need to embed Lato in the PDF
file.
```{r lato, eval = FALSE}
import_lato()
p <- ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point() +
scale_color_sage_d() +
theme_sage()
# Save PDF plot and embed Lato font
ggsave("plot.pdf", plot = p)
embed_fonts("plot.pdf", outfile = "plot_embed.pdf")
```
## Add logos
sagethemes allows you to add a logo to the bottom right of your plot with the
`logo_image()` and `logo_layout()` functions. By default it will use the Sage
Bionetworks logo, but you can also provide your own image, for example a
project-specific logo. This should be the last function call in your ggplot2
chain; you won't be able to add additional ggplot2 elements to the initial plot
after adding the logo.
```{r add-logo}
ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point() +
scale_color_sage_d() +
theme_sage() +
labs(
title = "Gas mileage",
subtitle = "Highway miles per gallon vs. engine displacement in liters"
) +
logo_image() +
logo_layout()
```
---
## Code of Conduct
Please note that the dccvalidator project is released with a [Contributor Code
of Conduct](.github/CODE_OF_CONDUCT.md). By contributing to this project, you
agree to abide by its terms.