Browse Source

palette + color/fill scales

tags/0.8.0
boB Rudis 7 years ago
parent
commit
ec6d7899bf
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 4
      NAMESPACE
  2. 27
      R/color.r
  3. 38
      README.Rmd
  4. 42
      README.md
  5. BIN
      README_files/figure-markdown_github/unnamed-chunk-6-1.png
  6. BIN
      README_files/figure-markdown_github/unnamed-chunk-7-1.png
  7. BIN
      README_files/figure-markdown_github/unnamed-chunk-8-1.png
  8. BIN
      README_files/figure-markdown_github/unnamed-chunk-9-1.png
  9. 15
      man/ipsum_pal.Rd
  10. 21
      man/scale_ipsum.Rd

4
NAMESPACE

@ -4,6 +4,10 @@ export(font_an)
export(font_rc)
export(font_rc_light)
export(import_roboto_condensed)
export(ipsum_pal)
export(scale_color_ipsum)
export(scale_colour_ipsum)
export(scale_fill_ipsum)
export(scale_x_comma)
export(scale_y_comma)
export(scale_y_percent)

27
R/color.r

@ -0,0 +1,27 @@
ipsum_palette <- c("#d18975", "#8fd175", "#3f2d54", "#75b8d1", "#2d543d", "#c9d175", "#d1ab75", "#d175b8", "#758bd1")
#' A muted, qualitative color palette
#'
#' @export
#' @examples
#' library(scales)
#' scales::show_col(ipsum_pal()(9))
ipsum_pal <- function() { manual_pal(ipsum_palette) }
#' Discrete color & fill scales based on the ipsum palette
#'
#' See [ipsum_pal]().
#'
#' @md
#' @inheritParams ggplot2::scale_colour_hue
#' @rdname scale_ipsum
#' @export
scale_colour_ipsum <- function(...) { discrete_scale("colour", "ipsum", ipsum_pal(), ...) }
#' @export
#' @rdname scale_ipsum
scale_color_ipsum <- scale_colour_ipsum
#' @export
#' @rdname scale_ipsum
scale_fill_ipsum <- function(...) { discrete_scale("fill", "ipsum", ipsum_pal(), ...) }

38
README.Rmd

@ -14,17 +14,11 @@ The following functions are implemented/objects are exported:
- `update_geom_font_defaults`: Update matching font defaults for text geoms (the default is — unsurprisingly — Arial Narrow)
- `scale_x_comma` / `scale_y_comma` : Comma format for axis text and `expand=c(0,0)` (you need to set limits)
- `scale_x_percent` / `scale_y_percent` : Percent format for axis text and `expand=c(0,0)` (you need to set limits)
- `scale_color_ipsum` / `scale_fill_ipsum` / `ipsum_pal` : A muted discrete color palette with 9 colors
- `font_an`: a short global alias for "`Arial Narrow`"
- `font_rc`: a short global alias for "`Roboto Condensed`"
- `font_rc_light`: a short global alias for "`Roboto Condensed Light`"
### TODO
- Creation of supplemental extra font packages with instructions for installation
- Additional base themes to match ^^
- At least one new custom color & fill scale
- Whatever ends up in a feature request in an issue that makes sense ;-)
### Installation
```{r eval=FALSE}
@ -39,6 +33,7 @@ options(width=120)
```{r message=FALSE, warning=FALSE, error=FALSE}
library(hrbrthemes)
library(gcookbook)
library(tidyverse)
# current verison
@ -69,7 +64,20 @@ ggplot(mtcars, aes(mpg, wt)) +
theme_ipsum_rc()
```
### Scales
### Scales (Color/Fill)
```{r fig.retina=2}
ggplot(mtcars, aes(mpg, wt)) +
geom_point(aes(color=factor(carb))) +
labs(x="Fuel effiiency (mpg)", y="Weight (tons)",
title="Seminal ggplot2 scatterplot example",
subtitle="A plot that is only useful for demonstration purposes",
caption="Brought to you by the letter 'g'") +
scale_color_ipsum() +
theme_ipsum_rc()
```
### Scales (Axis)
```{r fig.retina=2}
count(mpg, class) %>%
@ -84,6 +92,20 @@ count(mpg, class) %>%
theme_ipsum(grid="Y")
```
```{r fig.retina=2, fig.height=6}
ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) +
geom_area() +
scale_fill_ipsum() +
scale_x_continuous(expand=c(0,0)) +
scale_y_comma() +
labs(title="Age distribution of population in the U.S., 1900-2002",
subtitle="Example data from the R Graphics Cookbook",
caption="Source: R Graphics Cookbook") +
theme_ipsum_rc(grid="XY") +
theme(axis.text.x=element_text(hjust=c(0, 0.5, 0.5, 0.5, 1))) +
theme(legend.position="bottom")
```
```{r fig.retina=2}
update_geom_font_defaults(font_rc_light)

42
README.md

@ -12,6 +12,7 @@ The following functions are implemented/objects are exported:
- `update_geom_font_defaults`: Update matching font defaults for text geoms (the default is — unsurprisingly — Arial Narrow)
- `scale_x_comma` / `scale_y_comma` : Comma format for axis text and `expand=c(0,0)` (you need to set limits)
- `scale_x_percent` / `scale_y_percent` : Percent format for axis text and `expand=c(0,0)` (you need to set limits)
- `scale_color_ipsum` / `scale_fill_ipsum` / `ipsum_pal` : A muted discrete color palette with 9 colors
- `font_an`: a short global alias for "`Arial Narrow`"
- `font_rc`: a short global alias for "`Roboto Condensed`"
- `font_rc_light`: a short global alias for "`Roboto Condensed Light`"
@ -20,7 +21,6 @@ The following functions are implemented/objects are exported:
- Creation of supplemental extra font packages with instructions for installation
- Additional base themes to match ^^
- At least one new custom color & fill scale
- Whatever ends up in a feature request in an issue that makes sense ;-)
### Installation
@ -37,6 +37,7 @@ options(width=120)
``` r
library(hrbrthemes)
library(gcookbook)
library(tidyverse)
# current verison
@ -73,7 +74,22 @@ ggplot(mtcars, aes(mpg, wt)) +
<img src="README_files/figure-markdown_github/unnamed-chunk-5-1.png" width="672" />
### Scales
### Scales (Color/Fill)
``` r
ggplot(mtcars, aes(mpg, wt)) +
geom_point(aes(color=factor(carb))) +
labs(x="Fuel effiiency (mpg)", y="Weight (tons)",
title="Seminal ggplot2 scatterplot example",
subtitle="A plot that is only useful for demonstration purposes",
caption="Brought to you by the letter 'g'") +
scale_color_ipsum() +
theme_ipsum_rc()
```
<img src="README_files/figure-markdown_github/unnamed-chunk-6-1.png" width="672" />
### Scales (Axis)
``` r
count(mpg, class) %>%
@ -88,7 +104,23 @@ count(mpg, class) %>%
theme_ipsum(grid="Y")
```
<img src="README_files/figure-markdown_github/unnamed-chunk-6-1.png" width="672" />
<img src="README_files/figure-markdown_github/unnamed-chunk-7-1.png" width="672" />
``` r
ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) +
geom_area() +
scale_fill_ipsum() +
scale_x_continuous(expand=c(0,0)) +
scale_y_comma() +
labs(title="Age distribution of population in the U.S., 1900-2002",
subtitle="Example data from the R Graphics Cookbook",
caption="Source: R Graphics Cookbook") +
theme_ipsum_rc(grid="XY") +
theme(axis.text.x=element_text(hjust=c(0, 0.5, 0.5, 0.5, 1))) +
theme(legend.position="bottom")
```
<img src="README_files/figure-markdown_github/unnamed-chunk-8-1.png" width="672" />
``` r
update_geom_font_defaults(font_rc_light)
@ -109,7 +141,7 @@ count(mpg, class) %>%
theme_ipsum_rc(grid="X")
```
<img src="README_files/figure-markdown_github/unnamed-chunk-7-1.png" width="672" />
<img src="README_files/figure-markdown_github/unnamed-chunk-9-1.png" width="672" />
### Test Results
@ -120,7 +152,7 @@ library(testthat)
date()
```
## [1] "Sat Feb 11 16:16:12 2017"
## [1] "Sat Feb 11 17:07:33 2017"
``` r
test_dir("tests/")

BIN
README_files/figure-markdown_github/unnamed-chunk-6-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 83 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-7-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 77 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-8-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 129 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-9-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

15
man/ipsum_pal.Rd

@ -0,0 +1,15 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/color.r
\name{ipsum_pal}
\alias{ipsum_pal}
\title{A muted, qualitative color palette}
\usage{
ipsum_pal()
}
\description{
A muted, qualitative color palette
}
\examples{
library(scales)
scales::show_col(ipsum_pal()(9))
}

21
man/scale_ipsum.Rd

@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/color.r
\name{scale_colour_ipsum}
\alias{scale_colour_ipsum}
\alias{scale_color_ipsum}
\alias{scale_fill_ipsum}
\title{Discrete color & fill scales based on the ipsum palette}
\usage{
scale_colour_ipsum(...)
scale_color_ipsum(...)
scale_fill_ipsum(...)
}
\arguments{
\item{...}{Other arguments passed on to \code{\link{discrete_scale}}
to control name, limits, breaks, labels and so forth.}
}
\description{
See \url{ipsum_pal}.
}
Loading…
Cancel
Save