-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
95 lines (71 loc) · 2.67 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
warning = FALSE,
dpi = 300,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# mnbrand
<!-- badges: start -->
<!-- badges: end -->
The goal of **mnbrand** is to make it easier to implement the [official State of Minnesota color palette](https://mn.gov/portal/brand/style-guide/colors/) in ggplot2. This package also includes a theme function for flextable to create tables in R Markdown for Word and PowerPoint. Future versions of this package will include other functions/templates to implement the State of Minnesota branding in reports and other data products.
## Installation
You can install the development version of mnbrand from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("jfangmeier/mnbrand")
```
## Available Colors
The full list of brand colors is available with the `show_palette_mn` function.
```{r show_palette}
library(mnbrand)
show_palette_mn()
```
## Plot Examples
The mnbrand package can apply discrete palette colors (up to 10 colors) and continuous palette colors in ggplot2, depending on the variables being plotted. Here is an example using discrete colors with the `scale_color_mn_d` function:
```{r example1}
library(ggplot2)
mtcars %>%
ggplot(aes(x = mpg, y = hp, color = as.factor(carb))) +
geom_point(size = 4) +
scale_color_mn_d() +
theme_minimal()
```
When plotting with continuous variables, you can specify whether the continuous palette should be diverting and what value should be used as the diverging point. You can also specify which colors to use for continuous palettes. Here is an example without diverging with the `scale_fill_mn_c` function:
```{r example2, results='hide'}
library(tigris)
library(dplyr)
# download county boundaries with tigris package
mn_counties <- counties(state = "MN", progress_bar = FALSE)
# calculate share of area covered by water
mn_counties_pct_water <-
mn_counties %>%
transmute(WATER = AWATER / (AWATER + ALAND))
mn_counties_pct_water %>%
ggplot(aes(fill = WATER)) +
geom_sf() +
scale_fill_mn_c() +
theme_minimal() +
labs(title = "Share of County Covered by Water")
```
Here is an example with diverging colors with a specified diverging point and colors:
```{r example3}
mn_counties_pct_water %>%
ggplot(aes(fill = WATER)) +
geom_sf() +
scale_fill_mn_c(
diverge = TRUE,
high_color = "minnesota_blue",
low_color = "accent_orange",
midpoint = 0.2
) +
theme_minimal() +
labs(title = "Share of County Covered by Water")
```