-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
271 lines (186 loc) · 7.74 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
---
title: "usydColours"
author: "Jazmin Ozsvar"
date: "04/06/2020"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library("usydColours")
library("tidyverse")
library("knitr")
library("colorspace")
```
## The University of Sydney colour palettes
The `usydColours` package is intended to provide a set of colour palettes for use with `ggplot2` and `plot` graphs. The palettes have been derived from The University of Sydney Branding Document V2.0, and include the primary branding palette as well as some novelty palettes that capture the spirit and landmarks of the University.
For more information on University branding, refer to the following links:
* https://intranet.sydney.edu.au/services/marketing-communications/our-brand.html
* https://intranet.sydney.edu.au/content/dam/intranet/documents/services/marketing-communications/brand-documents/LR_Brand_Guidelines_V2.1_General.pdf
The functionality of usydColours is based on the wonderful `wesanderson` package (https://github.com/karthik/wesanderson).
### Installation
```{r installation, eval=FALSE, warnings=FALSE, message=FALSE}
library(devtools)
install_github("Sydney-Informatics-Hub/usydColours")
```
### Usage
Below is a list of the currently available palettes.
```{r usage, echo=FALSE, warnings=FALSE, message=FALSE}
# Grab all palette names
names(usyd_palettes)
```
### Qualitative palettes
```{r palettes_qualitative, echo=TRUE, warnings=FALSE, message=FALSE, fig.align='center', fig.width=5, fig.height=3}
# Primary
util_visualise_pal(usyd_palettes[["primary"]])
# Extended
util_visualise_pal(usyd_palettes[["extended"]])
# Secondary
util_visualise_pal(usyd_palettes[["secondary"]])
# Pastel
util_visualise_pal(usyd_palettes[["pastel"]])
# Bright
util_visualise_pal(usyd_palettes[["bright"]])
```
### Sequential palettes
```{r palettes_sequential, echo=TRUE, warnings=FALSE, message=FALSE, fig.align='center', fig.width=5, fig.height=3}
# Flame tree
util_visualise_pal(usyd_palettes[["flametree"]])
# Jacaranda
util_visualise_pal(usyd_palettes[["jacaranda"]])
# Sandstone
util_visualise_pal(usyd_palettes[["sandstone"]])
# Harbour
util_visualise_pal(usyd_palettes[["harbour"]])
# Ochre
util_visualise_pal(usyd_palettes[["ochre"]])
# Greyscale
util_visualise_pal(usyd_palettes[["greyscale"]])
```
### Diverging palettes
```{r palettes_diverging, echo=TRUE, warnings=FALSE, message=FALSE, fig.align='center', fig.width=5, fig.height=3}
# Modern (red/green)
util_visualise_pal(usyd_palettes[["modern_diverging"]])
# Complementary (red/green)
util_visualise_pal(usyd_palettes[["complementary_ReGr"]])
# Complementary (red/blue)
util_visualise_pal(usyd_palettes[["complementary_ReBl"]])
# Muted
util_visualise_pal(usyd_palettes[["muted"]])
# Traffic light
util_visualise_pal(usyd_palettes[["trafficlight"]])
# Diverging (blue/red)
util_visualise_pal(usyd_palettes[["diverging_blue_red"]])
# Diverging (blue/orange)
util_visualise_pal(usyd_palettes[["diverging_blue_orange"]])
```
### Use with ggplot2
Below are some examples of `usydColours` in action.
#### Categorical data
```{r usage_categorical, echo=TRUE, message=FALSE, warning=FALSE, fig.height=3, fig.align='center'}
# Bar graph with the primary palette
diamonds %>%
filter(price < 1000) %>%
ggplot(aes(price, fill = cut)) +
geom_histogram(colour = "black", position = "dodge", binwidth = 250) +
theme_bw() +
scale_fill_manual(values = usyd_palette("primary"))
# Density graph with the muted palette
iris %>%
ggplot(aes(x = Sepal.Length, fill = Species)) +
geom_density() +
theme_bw() +
facet_wrap(. ~ Species) +
scale_fill_manual(values = usyd_palette("muted"))
# Scatter plot using the jacaranda palette
diamonds %>%
filter(row_number() %% 5 == 1) %>%
filter(carat < 3) %>%
filter(clarity %in% c("SI2", "SI1", "VS2", "VVS2")) %>%
ggplot(aes(carat, price, colour = clarity)) +
geom_jitter(alpha = 0.7) +
theme_bw() +
scale_colour_manual(values = usyd_palette("jacaranda"))
```
#### Continuous data
Use `usyd_palette` to interpolate colours between the discrete colours of the available palettes for continuous data. Remember to supply values for `n` and set `type = "continuous"`.
Tip: you can also use `usyd_palette` to generate more colours of your favourite palette for categorical plots too!
```{r usage_continuous1, echo=TRUE, message=FALSE, warning=FALSE, fig.height=3, fig.align='center'}
# Heatmap
mpg %>%
count(class, drv) %>%
complete(class, drv, fill = list(n = 0L)) %>%
ggplot(aes(x = class, y = drv)) +
geom_tile(mapping = aes(fill = n)) +
theme_bw() +
scale_fill_gradientn(colours = usyd_palette("flametree", 100, type = "continuous"))
```
```{r usage_continuous2, echo=TRUE, message=FALSE, warning=FALSE, fig.height=3, fig.align='center'}
library(maps)
library(mapproj)
# Chloropleth
# This example is from: https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html
unemp <- read.csv("http://datasets.flowingdata.com/unemployment09.csv",
header = FALSE, stringsAsFactors = FALSE)
names(unemp) <- c("id", "state_fips", "county_fips", "name", "year",
"?", "?", "?", "rate")
unemp$county <- tolower(gsub(" County, [A-Z]{2}", "", unemp$name))
unemp$county <- gsub("^(.*) parish, ..$","\\1", unemp$county)
unemp$state <- gsub("^.*([A-Z]{2}).*$", "\\1", unemp$name)
county_df <- map_data("county", projection = "albers", parameters = c(39, 45))
names(county_df) <- c("long", "lat", "group", "order", "state_name", "county")
county_df$state <- state.abb[match(county_df$state_name, tolower(state.name))]
county_df$state_name <- NULL
state_df <- map_data("state", projection = "albers", parameters = c(39, 45))
choropleth <- merge(county_df, unemp, by = c("state", "county"))
choropleth <- choropleth[order(choropleth$order), ]
ggplot(choropleth, aes(long, lat, group = group)) +
geom_polygon(aes(fill = rate), colour = alpha("white", 1 / 2), size = 0.2) +
geom_polygon(data = state_df, colour = "white", fill = NA) +
coord_fixed() +
theme_void() +
ggtitle("US unemployment rate by county") +
theme(axis.line = element_blank(), axis.text = element_blank(),
axis.ticks = element_blank(), axis.title = element_blank()) +
scale_fill_gradientn(colours = usyd_palette("muted", 100, type = "continuous"))
```
### Defining custom palettes
Want to make your own palette? No problem! You can also define your own palette by selecting colours of your choice with `usyd_pal_gen`.
Below is the full list of colour names contained in `usydColours`.
```{r swatchplot, echo=FALSE, warning=FALSE, message=FALSE, fig.align='center'}
# Load required data
load(file = "R/sysdata.rda")
fullhexpallette <- matrix(sydneyunicolours$hex)
rownames(fullhexpallette) <- sydneyunicolours$colourName
# Display University branding colours
usydSwatchplot <- swatchplot(fullhexpallette)
```
After you've decided on what colours you want, use `usyd_pal_gen` as shown below to make a custom palette.
```{r new_palette, echo=TRUE, warning=FALSE, message=FALSE, fig.align='center', fig.height=4, fig.width=7}
# Define a new palette
my_palette <- usyd_pal_gen(
"UpdatedOchre",
"LightOchre",
"NeutralGrey",
"Eucalypt",
"DarkEucalypt")
# Use the new palette
diamonds %>%
filter(price < 1000) %>%
ggplot(aes(price, fill = cut)) +
geom_histogram(colour = "black", position = "dodge", binwidth = 250) +
theme_bw() +
scale_fill_manual(values = my_palette)
```
### RGB values and hex codes of colours
You can also refer to this table for RGB values and hex codes if you'd like to apply them in Photoshop or any other code.
```{r hexcodes, echo=FALSE, warning=FALSE, message=FALSE}
sydneyunicolours2 <- sydneyunicolours %>%
dplyr::select(
colourName,
R,
G,
B,
hex
)
knitr::kable(sydneyunicolours2)
```