Преглед на файлове

Add fancy theme, do not change font by default

pull/4/head
Garrick Aden-Buie преди 8 години
родител
ревизия
bb8efcfe46
променени са 18 файла, в които са добавени 110 реда и са изтрити 91 реда
  1. +1
    -1
      DESCRIPTION
  2. +1
    -0
      NAMESPACE
  3. +3
    -0
      NEWS.md
  4. +18
    -20
      R/theme_pomological.R
  5. +30
    -27
      Readme.Rmd
  6. +44
    -34
      Readme.md
  7. Двоични данни
      Readme_files/figure-gfm/ggpomological.png
  8. Двоични данни
      Readme_files/figure-gfm/plot-bar-chart-1.png
  9. Двоични данни
      Readme_files/figure-gfm/plot-bar-chart-painted.png
  10. Двоични данни
      Readme_files/figure-gfm/plot-demo-3.png
  11. Двоични данни
      Readme_files/figure-gfm/plot-demo-4.png
  12. Двоични данни
      Readme_files/figure-gfm/plot-demo-painted.png
  13. Двоични данни
      Readme_files/figure-gfm/plot-density-1.png
  14. Двоични данни
      Readme_files/figure-gfm/plot-density-demo-painted.png
  15. Двоични данни
      Readme_files/figure-gfm/plot-full-bar-stack-1.png
  16. Двоични данни
      Readme_files/figure-gfm/plot-full-bar-stack-painted.png
  17. Двоични данни
      Readme_files/figure-gfm/plot-ridges-painted.png
  18. +13
    -9
      man/theme_pomological.Rd

+ 1
- 1
DESCRIPTION Целия файл

@@ -1,5 +1,5 @@
Package: ggpomological
Version: 0.1.0
Version: 0.1.1
Title: Pomological plot themes for ggplot2
Description: Pomological plot themes and scales for ggplot2 (in progress)
Authors@R: person("Garrick", "Aden-Buie", , "g.adenbuie@gmail.com", c("aut", "cre"))

+ 1
- 0
NAMESPACE Целия файл

@@ -5,5 +5,6 @@ export(scale_color_pomological)
export(scale_colour_pomological)
export(scale_fill_pomological)
export(theme_pomological)
export(theme_pomological_fancy)
export(theme_pomological_nobg)
export(theme_pomological_plain)

+ 3
- 0
NEWS.md Целия файл

@@ -0,0 +1,3 @@
# ggpomological 0.1.1

* Do not mess with fonts as default values of `theme_pomological()`. Created `theme_pomological_fancy()` as wrapper with fancy font defaults instead.

+ 18
- 20
R/theme_pomological.R Целия файл

@@ -48,15 +48,13 @@
#' basic_iris_plot +
#' theme_pomological()
#'
#' # Don't change panel grid color
#' # With fonts (manual)
#' basic_iris_plot +
#' theme_pomological(
#' panel.grid.color = NULL
#' )
#' theme_pomological("Homemade Apple", 16)
#'
#' # White background
#' # Or with fancy alias (same as previous)
#' basic_iris_plot +
#' theme_pomological_nobg()
#' theme_pomological_fancy()
#'
#' # Plain plot without font or background
#' basic_iris_plot +
@@ -64,8 +62,8 @@
#'
#' @export
theme_pomological <- function(
base_family = "Homemade Apple",
base_size = 14,
base_family = NULL,
base_size = 11,
text.color = pomological_base$dark_blue,
plot.background.color = pomological_base$paper,
panel.border.color = pomological_base$light_line,
@@ -81,7 +79,7 @@ theme_pomological <- function(
base_theme +
ggplot2::theme(
text = ggplot2::element_text(
family = base_family,
family = if (!is.null(base_family)) base_family,
size = base_size,
colour = text.color
),
@@ -108,21 +106,21 @@ theme_pomological <- function(

#' @describeIn theme_pomological Pomological theme with white (transparent) background
#' @export
theme_pomological_nobg <- function(...) {
dots <- list(...)
dots$plot.background.color <- "transparent"
do.call("theme_pomological", args = dots)
theme_pomological_nobg <- function(..., plot.background.color = "transparent") {
theme_pomological(plot.background.color = plot.background.color, ...)
}

#' @describeIn theme_pomological A "plain" pomological theme with white
#' background and normal fonts.
#' background and normal fonts.
#' @export
theme_pomological_plain <- function(...) {
dots <- list(...)
dots$plot.background.color <- "transparent"
if (!"base_family" %in% names(dots)) dots["base_family"] <- ""
if (!"base_size" %in% names(dots)) dots["base_size"] <- 11
do.call("theme_pomological", args = dots)
theme_pomological_plain <- function(base_family = "", base_size = 11, plot.background.color = "transparent", ...) {
theme_pomological(base_family, base_size, plot.background.color = plot.background.color, ...)
}

#' @describeIn theme_pomological A "fancy" pomological theme with fancy fonts
#' @export
theme_pomological_fancy <- function(base_family = "Homemade Apple", base_size = 16, ...) {
theme_pomological(base_family, base_size, ...)
}

font_urls <- data.frame(

+ 30
- 27
Readme.Rmd Целия файл

@@ -1,7 +1,6 @@
---
title: "Pomological Colors"
author: "Garrick Aden-Buie"
date: "2/4/2018"
output: github_document
editor_options:
chunk_output_type: console
@@ -13,8 +12,6 @@ library(ggpomological)
library(dplyr)
```

## Pomological Plots


<!-- Links -->
[rstudioconf]: https://www.rstudio.com/conference/
@@ -38,7 +35,7 @@ readr::read_tsv("https://cs.joensuu.fi/sipu/datasets/Compound.txt", col_names =
labs(x = "Space", y = "Time",
color = "Fruit", title = "ggpomological") +
scale_color_pomological() +
theme_pomological()
theme_pomological_fancy()
} %>%
paint_pomological(res = 110) %>%
magick::image_write("Readme_files/figure-gfm/ggpomological.png")
@@ -46,7 +43,7 @@ readr::read_tsv("https://cs.joensuu.fi/sipu/datasets/Compound.txt", col_names =

![](Readme_files/figure-gfm/ggpomological.png)

![](Readme_files/pom-examples.jpg)
![](Readme_files/pom-examples.jpg)^[U.S. Department of Agriculture Pomological Watercolor Collection. Rare and Special Collections, National Agricultural Library, Beltsville, MD 20705]

## Installation

@@ -82,18 +79,10 @@ There are three theme-generating functions:

- `theme_pomological()` sets the plot theme to be representative of the paper and styling of the watercolors and includes a paper-colored background,

- `theme_pomological_nobg()` has the same styling, just with a transparent (or white) background,
- `theme_pomological_plain()` has the same styling, just with a transparent (or white) background,

- `theme_pomological_plain()` has a white background and doesn't change the font unless requested.
- `theme_pomological_fancy()` has the paper-colored background and defaults to a fancy handwritten font ([Homemade Apple](https://fonts.google.com/specimen/Homemade+Apple/)).

A handwriting font is needed for the fully authentic pomological look, and I found a few from Google Fonts that fit the bill.

- [Mr. De Haviland](https://fonts.google.com/specimen/Mr+De+Haviland)
- [Homemade Apple](https://fonts.google.com/specimen/Homemade+Apple/)
- [Marck Script](https://fonts.google.com/specimen/Marck+Script/)
- [Mr. Bedfort](https://fonts.google.com/specimen/Mr+Bedfort/)

Alternatively, use something like [calligrapher.com](https://www.calligraphr.com/) to create your own handwriting font!

For color and fill scales, **ggpomological** provides `scale_color_pomological()` and `scale_fill_pomological()`.

@@ -105,6 +94,19 @@ In the future, I might revisit this package to

3. Set up continuous scale colors (we'll see...)

## Fonts

A handwriting font is needed for the fully authentic pomological look, and I found a few from Google Fonts that fit the bill.

- [Mr. De Haviland](https://fonts.google.com/specimen/Mr+De+Haviland)
- [Homemade Apple](https://fonts.google.com/specimen/Homemade+Apple/)
- [Marck Script](https://fonts.google.com/specimen/Marck+Script/)
- [Mr. Bedfort](https://fonts.google.com/specimen/Mr+Bedfort/)

Alternatively, use something like [calligrapher.com](https://www.calligraphr.com/) to create your own handwriting font!

But fonts can be painful in R, so the base functions -- `theme_pomological()` and `theme_pomological_plain()` -- don't change the font by default.
To opt into the full pomological effect, use `theme_pomological_fancy()` which is just an alias for `theme_pomological(base_family = "Homemade Apple", base_size = 16)`.

## Add paper background!

@@ -120,6 +122,8 @@ library(ggpomological)
library(dplyr)
```

**Warning**: If you don't have the [above fonts](#fonts) installed, you'll get an error message with a lot of warnings when running the below examples. Just replace `theme_pomological("Homemade Apple", 16)` with `theme_pomological()` for the basic theme without the crazy fonts.

### Basic iris plot

```{r plot-demo}
@@ -136,15 +140,14 @@ basic_iris_plot <- basic_iris_plot + scale_color_pomological()
basic_iris_plot

# With pomological theme
pomological_iris <- basic_iris_plot + theme_pomological()
pomological_iris
basic_iris_plot + theme_pomological()

# With transparent background
basic_iris_plot + theme_pomological_nobg()

# Or with "plain" pomological
basic_iris_plot + theme_pomological_plain()

# Or with "fancy" pomological settings
pomological_iris <- basic_iris_plot + theme_pomological_fancy()

# Painted!
paint_pomological(pomological_iris, res = 110) %>%
magick::image_write("Readme_files/figure-gfm/plot-demo-painted.png")
@@ -165,10 +168,10 @@ stacked_bar_plot <- ggplot(diamonds) +
scale_x_continuous(label = scales::dollar_format()) +
scale_fill_pomological()

stacked_bar_plot + theme_pomological()
stacked_bar_plot + theme_pomological("Homemade Apple", 16)

paint_pomological(
stacked_bar_plot + theme_pomological_nobg(),
stacked_bar_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-bar-chart-painted.png")
@@ -188,10 +191,10 @@ density_plot <- mtcars %>%
scale_color_pomological() +
scale_fill_pomological()

density_plot + theme_pomological()
density_plot + theme_pomological("Homemade Apple", 16)

paint_pomological(
density_plot + theme_pomological_nobg(),
density_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-density-demo-painted.png")
@@ -225,10 +228,10 @@ full_bar_stack_plot <- txhousing %>%
theme(panel.grid.minor.x = element_blank()) +
scale_fill_pomological()

full_bar_stack_plot + theme_pomological()
full_bar_stack_plot + theme_pomological("Homemade Apple", 16)

paint_pomological(
full_bar_stack_plot + theme_pomological_nobg(),
full_bar_stack_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-full-bar-stack-painted.png")
@@ -244,7 +247,7 @@ Using my own handwriting and the `ggridges` package.
ridges_pomological <- ggplot(diamonds) +
aes(x = carat, y = clarity, color = clarity, fill = clarity) +
ggridges::geom_density_ridges(alpha = 0.75) +
theme_pomological_nobg(
theme_pomological(
base_family = 'gWriting',
base_size = 20,
base_theme = ggridges::theme_ridges()

+ 44
- 34
Readme.md Целия файл

@@ -1,9 +1,6 @@
Pomological Colors
================
Garrick Aden-Buie
2/4/2018

## Pomological Plots

<!-- Links -->

@@ -15,7 +12,7 @@ parameterized RMarkdown](https://youtu.be/Ol1FjFR2IMU?t=5h21m15s) at

![](Readme_files/figure-gfm/ggpomological.png)

![](Readme_files/pom-examples.jpg)
![](Readme_files/pom-examples.jpg)\[1\]

## Installation

@@ -61,11 +58,26 @@ There are three theme-generating functions:
the paper and styling of the watercolors and includes a
paper-colored background,

- `theme_pomological_nobg()` has the same styling, just with a
- `theme_pomological_plain()` has the same styling, just with a
transparent (or white) background,

- `theme_pomological_plain()` has a white background and doesn’t
change the font unless requested.
- `theme_pomological_fancy()` has the paper-colored background and
defaults to a fancy handwritten font ([Homemade
Apple](https://fonts.google.com/specimen/Homemade+Apple/)).

For color and fill scales, **ggpomological** provides
`scale_color_pomological()` and `scale_fill_pomological()`.

In the future, I might revisit this package to

1. Increase colors in discrete scale

2. Setup paired color scales. Lots of great color pairs in the
extracted colors.

3. Set up continuous scale colors (we’ll see…)

## Fonts

A handwriting font is needed for the fully authentic pomological look,
and I found a few from Google Fonts that fit the bill.
@@ -79,17 +91,11 @@ Alternatively, use something like
[calligrapher.com](https://www.calligraphr.com/) to create your own
handwriting font\!

For color and fill scales, **ggpomological** provides
`scale_color_pomological()` and `scale_fill_pomological()`.

In the future, I might revisit this package to

1. Increase colors in discrete scale

2. Setup paired color scales. Lots of great color pairs in the
extracted colors.

3. Set up continuous scale colors (we’ll see…)
But fonts can be painful in R, so the base functions –
`theme_pomological()` and `theme_pomological_plain()` – don’t change the
font by default. To opt into the full pomological effect, use
`theme_pomological_fancy()` which is just an alias for
`theme_pomological(base_family = "Homemade Apple", base_size = 16)`.

## Add paper background\!

@@ -108,6 +114,11 @@ library(ggpomological)
library(dplyr)
```

**Warning**: If you don’t have the [above fonts](#fonts) installed,
you’ll get an error message with a lot of warnings when running the
below examples. Just replace `theme_pomological("Homemade Apple", 16)`
with `theme_pomological()` for the basic theme without the crazy fonts.

### Basic iris plot

``` r
@@ -132,27 +143,22 @@ basic_iris_plot

``` r
# With pomological theme
pomological_iris <- basic_iris_plot + theme_pomological()
pomological_iris
basic_iris_plot + theme_pomological()
```

![](Readme_files/figure-gfm/plot-demo-3.png)<!-- -->

``` r
# With transparent background
basic_iris_plot + theme_pomological_nobg()
basic_iris_plot + theme_pomological_plain()
```

![](Readme_files/figure-gfm/plot-demo-4.png)<!-- -->

``` r
# Or with "plain" pomological
basic_iris_plot + theme_pomological_plain()
```

![](Readme_files/figure-gfm/plot-demo-5.png)<!-- -->
# Or with "fancy" pomological settings
pomological_iris <- basic_iris_plot + theme_pomological_fancy()

``` r
# Painted!
paint_pomological(pomological_iris, res = 110) %>%
magick::image_write("Readme_files/figure-gfm/plot-demo-painted.png")
@@ -172,14 +178,14 @@ stacked_bar_plot <- ggplot(diamonds) +
scale_x_continuous(label = scales::dollar_format()) +
scale_fill_pomological()

stacked_bar_plot + theme_pomological()
stacked_bar_plot + theme_pomological("Homemade Apple", 16)
```

![](Readme_files/figure-gfm/plot-bar-chart-1.png)<!-- -->

``` r
paint_pomological(
stacked_bar_plot + theme_pomological_nobg(),
stacked_bar_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-bar-chart-painted.png")
@@ -199,14 +205,14 @@ density_plot <- mtcars %>%
scale_color_pomological() +
scale_fill_pomological()

density_plot + theme_pomological()
density_plot + theme_pomological("Homemade Apple", 16)
```

![](Readme_files/figure-gfm/plot-density-1.png)<!-- -->

``` r
paint_pomological(
density_plot + theme_pomological_nobg(),
density_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-density-demo-painted.png")
@@ -243,14 +249,14 @@ full_bar_stack_plot <- txhousing %>%
theme(panel.grid.minor.x = element_blank()) +
scale_fill_pomological()

full_bar_stack_plot + theme_pomological()
full_bar_stack_plot + theme_pomological("Homemade Apple", 16)
```

![](Readme_files/figure-gfm/plot-full-bar-stack-1.png)<!-- -->

``` r
paint_pomological(
full_bar_stack_plot + theme_pomological_nobg(),
full_bar_stack_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-full-bar-stack-painted.png")
@@ -266,7 +272,7 @@ Using my own handwriting and the `ggridges` package.
ridges_pomological <- ggplot(diamonds) +
aes(x = carat, y = clarity, color = clarity, fill = clarity) +
ggridges::geom_density_ridges(alpha = 0.75) +
theme_pomological_nobg(
theme_pomological(
base_family = 'gWriting',
base_size = 20,
base_theme = ggridges::theme_ridges()
@@ -281,3 +287,7 @@ paint_pomological(ridges_pomological, res = 110) %>%
## Picking joint bandwidth of 0.057

![](Readme_files/figure-gfm/plot-ridges-painted.png)

1. U.S. Department of Agriculture Pomological Watercolor Collection.
Rare and Special Collections, National Agricultural Library,
Beltsville, MD 20705

Двоични данни
Readme_files/figure-gfm/ggpomological.png Целия файл

Before After
Width: 800  |  Height: 500  |  Size: 563KB Width: 800  |  Height: 500  |  Size: 566KB

Двоични данни
Readme_files/figure-gfm/plot-bar-chart-1.png Целия файл

Before After
Width: 768  |  Height: 480  |  Size: 38KB Width: 768  |  Height: 480  |  Size: 43KB

Двоични данни
Readme_files/figure-gfm/plot-bar-chart-painted.png Целия файл

Before After
Width: 800  |  Height: 500  |  Size: 531KB Width: 800  |  Height: 500  |  Size: 537KB

Двоични данни
Readme_files/figure-gfm/plot-demo-3.png Целия файл

Before After
Width: 768  |  Height: 480  |  Size: 53KB Width: 768  |  Height: 480  |  Size: 43KB

Двоични данни
Readme_files/figure-gfm/plot-demo-4.png Целия файл

Before After
Width: 768  |  Height: 480  |  Size: 53KB Width: 768  |  Height: 480  |  Size: 43KB

Двоични данни
Readme_files/figure-gfm/plot-demo-painted.png Целия файл

Before After
Width: 800  |  Height: 500  |  Size: 534KB Width: 800  |  Height: 500  |  Size: 538KB

Двоични данни
Readme_files/figure-gfm/plot-density-1.png Целия файл

Before After
Width: 768  |  Height: 480  |  Size: 47KB Width: 768  |  Height: 480  |  Size: 50KB

Двоични данни
Readme_files/figure-gfm/plot-density-demo-painted.png Целия файл

Before After
Width: 800  |  Height: 500  |  Size: 515KB Width: 800  |  Height: 500  |  Size: 518KB

Двоични данни
Readme_files/figure-gfm/plot-full-bar-stack-1.png Целия файл

Before After
Width: 768  |  Height: 480  |  Size: 48KB Width: 768  |  Height: 480  |  Size: 52KB

Двоични данни
Readme_files/figure-gfm/plot-full-bar-stack-painted.png Целия файл

Before After
Width: 800  |  Height: 500  |  Size: 509KB Width: 800  |  Height: 500  |  Size: 523KB

Двоични данни
Readme_files/figure-gfm/plot-ridges-painted.png Целия файл

Before After
Width: 800  |  Height: 500  |  Size: 528KB Width: 800  |  Height: 500  |  Size: 528KB

+ 13
- 9
man/theme_pomological.Rd Целия файл

@@ -4,9 +4,10 @@
\alias{theme_pomological}
\alias{theme_pomological_nobg}
\alias{theme_pomological_plain}
\alias{theme_pomological_fancy}
\title{Pomological Theme}
\usage{
theme_pomological(base_family = "Homemade Apple", base_size = 18,
theme_pomological(base_family = NULL, base_size = 11,
text.color = pomological_base$dark_blue,
plot.background.color = pomological_base$paper,
panel.border.color = pomological_base$light_line, with.panel.grid = FALSE,
@@ -15,9 +16,12 @@ theme_pomological(base_family = "Homemade Apple", base_size = 18,
axis.text.color = pomological_base$medium_line, axis.text.size = base_size
* 3/4, base_theme = ggplot2::theme_minimal())

theme_pomological_nobg(...)
theme_pomological_nobg(..., plot.background.color = "transparent")

theme_pomological_plain(...)
theme_pomological_plain(base_family = "", base_size = 11,
plot.background.color = "transparent", ...)

theme_pomological_fancy(base_family = "Homemade Apple", base_size = 16, ...)
}
\arguments{
\item{base_family}{Base text family. See \strong{Fonts} in \code{\link[=theme_pomological]{theme_pomological()}}
@@ -54,6 +58,8 @@ to \code{NULL}.}

\item \code{theme_pomological_plain}: A "plain" pomological theme with white
background and normal fonts.

\item \code{theme_pomological_fancy}: A "fancy" pomological theme with fancy fonts
}}

\section{Fonts}{
@@ -86,15 +92,13 @@ basic_iris_plot <- ggplot(iris) +
basic_iris_plot +
theme_pomological()

# Don't change panel grid color
# With fonts (manual)
basic_iris_plot +
theme_pomological(
panel.grid.color = NULL
)
theme_pomological("Homemade Apple", 16)
# White background
# Or with fancy alias (same as previous)
basic_iris_plot +
theme_pomological_nobg()
theme_pomological_fancy()
# Plain plot without font or background
basic_iris_plot +

Loading…
Отказ
Запис