Procházet zdrojové kódy

Add vignette (copy of readme)

pull/4/head
Garrick Aden-Buie před 8 roky
rodič
revize
c3e6afc8ec
29 změnil soubory, kde provedl 307 přidání a 282 odebrání
  1. +1
    -0
      .gitignore
  2. +7
    -1
      DESCRIPTION
  3. +7
    -1
      NEWS.md
  4. +4
    -239
      Readme.Rmd
  5. +44
    -41
      Readme.md
  6. binární
      Readme_files/figure-gfm/ggpomological-1.png
  7. binární
      Readme_files/figure-gfm/ggpomological.png
  8. binární
      Readme_files/figure-gfm/plot-bar-chart-1.png
  9. binární
      Readme_files/figure-gfm/plot-bar-chart-2.png
  10. binární
      Readme_files/figure-gfm/plot-bar-chart-painted.png
  11. binární
      Readme_files/figure-gfm/plot-demo-1.png
  12. binární
      Readme_files/figure-gfm/plot-demo-2.png
  13. binární
      Readme_files/figure-gfm/plot-demo-3.png
  14. binární
      Readme_files/figure-gfm/plot-demo-4.png
  15. binární
      Readme_files/figure-gfm/plot-demo-painted.png
  16. binární
      Readme_files/figure-gfm/plot-density-1.png
  17. binární
      Readme_files/figure-gfm/plot-density-2.png
  18. binární
      Readme_files/figure-gfm/plot-density-demo-painted.png
  19. binární
      Readme_files/figure-gfm/plot-full-bar-stack-1.png
  20. binární
      Readme_files/figure-gfm/plot-full-bar-stack-2.png
  21. binární
      Readme_files/figure-gfm/plot-full-bar-stack-painted.png
  22. binární
      Readme_files/figure-gfm/plot-points-lines-1.png
  23. binární
      Readme_files/figure-gfm/plot-ridges-1.png
  24. binární
      Readme_files/figure-gfm/unnamed-chunk-1-1.png
  25. binární
      Readme_files/figure-gfm/unnamed-chunk-1-2.png
  26. binární
      Readme_files/pom-examples.jpg
  27. +1
    -0
      pomological.Rproj
  28. +2
    -0
      vignettes/.gitignore
  29. +241
    -0
      vignettes/ggpomological.Rmd

+ 1
- 0
.gitignore Zobrazit soubor

@@ -1,3 +1,4 @@
.Rhistory
.RData
.Rproj.user
inst/doc

+ 7
- 1
DESCRIPTION Zobrazit soubor

@@ -1,5 +1,5 @@
Package: ggpomological
Version: 0.1.1
Version: 0.1.2
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"))
@@ -16,3 +16,9 @@ Depends:
Imports:
magick,
extrafont
Suggests:
knitr,
rmarkdown,
dplyr,
here
VignetteBuilder: knitr

+ 7
- 1
NEWS.md Zobrazit soubor

@@ -1,3 +1,9 @@
# ggpomological 0.1.1
# ggpomological 0.1

## v0.1.2

* Copied README to `vignettes/ggpomological`.

## v0.1.1

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

+ 4
- 239
Readme.Rmd Zobrazit soubor

@@ -6,44 +6,6 @@ editor_options:
chunk_output_type: console
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.width=8, fig.height=5)
library(ggpomological)
library(dplyr)
```


<!-- Links -->
[rstudioconf]: https://www.rstudio.com/conference/
[t-aronatkins]: https://twitter.com/aronatkins
[rsconf-slides]: https://github.com/rstudio/rstudio-conf/tree/master/2018/Fruit_For_Thought--Aron_Atkins
[rsconf-video]: https://youtu.be/Ol1FjFR2IMU?t=5h21m15s
[usda-pom]: https://usdawatercolors.nal.usda.gov/pom
[t-pomological]: https://twitter.com/pomological
[magick]: https://cran.r-project.org/web/packages/magick/index.html

This package provides a ggplot2 theme inspired by the [USDA Pomological Watercolors collection][usda-pom] and by Aron Atkins's ([\@aronatkins][t-aronatkins]) [talk on parameterized RMarkdown][rsconf-video] at [rstudio::conf 2018][rstudioconf].

```{r header-demo, echo=FALSE, message=FALSE, warning=FALSE}
fruits <- c("Apple", "Apricot", "Banana", "Fig", "Cherry", "Kiwi", "Grape", "Mango", "Papaya", "Orange", "Peach", "Pear")
readr::read_tsv("https://cs.joensuu.fi/sipu/datasets/Compound.txt", col_names = FALSE) %>%
filter(X3 < 10) %>%
mutate(X3 = sample(fruits, length(unique(X3)))[X3]) %>%
{
ggplot(., aes(x = X1, y = X2, color = X3)) +
geom_point() +
labs(x = "Space", y = "Time",
color = "Fruit", title = "ggpomological") +
scale_color_pomological() +
theme_pomological_fancy()
} %>%
paint_pomological(res = 110) %>%
magick::image_write("Readme_files/figure-gfm/ggpomological.png")
```

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

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

## Installation

@@ -54,209 +16,12 @@ This package isn't on CRAN, so you'll need to use the devtools package to instal
install.packages("devtools")

devtools::install_github("gadenbuie/ggpomological")
```

## Color Palette

The colors for this theme were drawn from many images from the [USDA Pomological Watercolors collection][usda-pom], I chose just a few that I thought worked well together for color and fill scales

```{r}
scales::show_col(ggpomological:::pomological_palette)
```

and a few colors for the plot background and decoration

```{r}
scales::show_col(unlist(ggpomological:::pomological_base))
```

I've also included a [css file](inst/pomological.css) with the complete collection of color samples.


## Setup theme and scales

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_plain()` has the same styling, just with a transparent (or white) background,

- `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.

- [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!

**ggpomological** also provides a function named `paint_pomological` that uses the [`magick`][magick] package to add a pomological watercolor paper background and a subtle texture overlay.


## Demo!

We'll need ggplot2 (loaded with **ggpomological**) and dplyr

```r
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}
# Base plot
basic_iris_plot <- ggplot(iris) +
aes(x = Sepal.Length, y = Sepal.Width, color = Species) +
geom_point(size = 2)

# Just your standard Iris plot
basic_iris_plot

# With pomological colors
basic_iris_plot <- basic_iris_plot + scale_color_pomological()
basic_iris_plot

# With pomological theme
basic_iris_plot + theme_pomological()

# With transparent background
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")
```

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

### Stacked bar chart


```{r plot-bar-chart}
stacked_bar_plot <- ggplot(diamonds) +
aes(price, fill = cut) +
geom_histogram(binwidth = 850) +
xlab('Price (USD)') +
ylab('Count') +
ggtitle("ggpomological") +
scale_x_continuous(label = scales::dollar_format()) +
scale_fill_pomological()

stacked_bar_plot + theme_pomological("Homemade Apple", 16)

paint_pomological(
stacked_bar_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-bar-chart-painted.png")
# To include the vignette
devtools::install_github("gadenbuie/ggpomological", build_vignettes=TRUE)
```

![](Readme_files/figure-gfm/plot-bar-chart-painted.png)
## Introduction

### Density Plot

```{r plot-density}
density_plot <- mtcars %>%
mutate(cyl = factor(cyl)) %>%
ggplot() +
aes(mpg, fill = cyl, color = cyl)+
geom_density(alpha = 0.75) +
labs(fill = 'Cylinders', colour = 'Cylinders', x = 'MPG', y = 'Density') +
scale_color_pomological() +
scale_fill_pomological()

density_plot + theme_pomological("Homemade Apple", 16)

paint_pomological(
density_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-density-demo-painted.png")
```{r readme, child = "vignettes/ggpomological.Rmd", out.dir="Readme_files/figure-gfm/"}
```

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


### Points and lines

Data from the Texas Housing

```{r plot-full-bar-stack}
big_volume_cities <- txhousing %>%
group_by(city) %>%
summarize(mean_volume = mean(volume, na.rm = TRUE)) %>%
arrange(-mean_volume) %>%
top_n(length(ggpomological:::pomological_palette)) %>%
pull(city)

full_bar_stack_plot <- txhousing %>%
filter(city %in% big_volume_cities) %>%
group_by(city, year) %>%
summarize(mean_volume = mean(volume, na.rm = TRUE)) %>%
ungroup %>%
mutate(city = factor(city, big_volume_cities)) %>%
ggplot() +
aes(year, mean_volume, fill = city, group = city) +
geom_col(position = 'fill', width = 0.9) +
labs(x = 'City', y = 'Mean Volume', color = 'City') +
theme(panel.grid.minor.x = element_blank()) +
scale_fill_pomological()

full_bar_stack_plot + theme_pomological("Homemade Apple", 16)

paint_pomological(
full_bar_stack_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-full-bar-stack-painted.png")
```

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

### One last plot

Using my own handwriting and the `ggridges` package.

```{r plot-ridges}
ridges_pomological <- ggplot(diamonds) +
aes(x = carat, y = clarity, color = clarity, fill = clarity) +
ggridges::geom_density_ridges(alpha = 0.75) +
theme_pomological(
base_family = 'gWriting',
base_size = 20,
base_theme = ggridges::theme_ridges()
) +
scale_fill_pomological() +
scale_color_pomological()

paint_pomological(ridges_pomological, res = 110) %>%
magick::image_write("Readme_files/figure-gfm/plot-ridges-painted.png")
```

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

+ 44
- 41
Readme.md Zobrazit soubor

@@ -2,18 +2,6 @@ Pomological Colors
================
Garrick Aden-Buie

<!-- Links -->

This package provides a ggplot2 theme inspired by the [USDA Pomological
Watercolors collection](https://usdawatercolors.nal.usda.gov/pom) and by
Aron Atkins’s ([@aronatkins](https://twitter.com/aronatkins)) [talk on
parameterized RMarkdown](https://youtu.be/Ol1FjFR2IMU?t=5h21m15s) at
[rstudio::conf 2018](https://www.rstudio.com/conference/).

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

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

## Installation

This package isn’t on CRAN, so you’ll need to use the devtools package
@@ -24,8 +12,25 @@ to install it.
install.packages("devtools")

devtools::install_github("gadenbuie/ggpomological")

# To include the vignette
devtools::install_github("gadenbuie/ggpomological", build_vignettes=TRUE)
```

## Introduction

<!-- Links -->

This package provides a ggplot2 theme inspired by the [USDA Pomological
Watercolors collection](https://usdawatercolors.nal.usda.gov/pom) and by
Aron Atkins’s ([@aronatkins](https://twitter.com/aronatkins)) [talk on
parameterized RMarkdown](https://youtu.be/Ol1FjFR2IMU?t=5h21m15s) at
[rstudio::conf 2018](https://www.rstudio.com/conference/).

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

![](Readme_files/pom-examples.jpg)<!-- -->[^1]

## Color Palette

The colors for this theme were drawn from many images from the [USDA
@@ -37,7 +42,7 @@ few that I thought worked well together for color and fill scales
scales::show_col(ggpomological:::pomological_palette)
```

![](Readme_files/figure-gfm/unnamed-chunk-1-1.png)<!-- -->
![](Readme_files/figure-gfm/unnamed-chunk-1-2.png)<!-- -->

and a few colors for the plot background and decoration

@@ -131,40 +136,43 @@ basic_iris_plot <- ggplot(iris) +
basic_iris_plot
```

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

``` r

# With pomological colors
basic_iris_plot <- basic_iris_plot + scale_color_pomological()
basic_iris_plot
```

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

``` r

# With pomological theme
basic_iris_plot + theme_pomological()
```

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

``` r

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

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

``` r

# 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")
paint_pomological(pomological_iris, res = 110)
```

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

### Stacked bar chart

@@ -181,17 +189,17 @@ stacked_bar_plot <- ggplot(diamonds) +
stacked_bar_plot + theme_pomological("Homemade Apple", 16)
```

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

``` r

paint_pomological(
stacked_bar_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-bar-chart-painted.png")
)
```

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

### Density Plot

@@ -208,17 +216,17 @@ density_plot <- mtcars %>%
density_plot + theme_pomological("Homemade Apple", 16)
```

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

``` r

paint_pomological(
density_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-density-demo-painted.png")
)
```

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

### Points and lines

@@ -231,11 +239,8 @@ big_volume_cities <- txhousing %>%
arrange(-mean_volume) %>%
top_n(length(ggpomological:::pomological_palette)) %>%
pull(city)
```

## Selecting by mean_volume
#> Selecting by mean_volume

``` r
full_bar_stack_plot <- txhousing %>%
filter(city %in% big_volume_cities) %>%
group_by(city, year) %>%
@@ -252,17 +257,17 @@ full_bar_stack_plot <- txhousing %>%
full_bar_stack_plot + theme_pomological("Homemade Apple", 16)
```

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

``` r

paint_pomological(
full_bar_stack_plot + theme_pomological_fancy(),
res = 110
) %>%
magick::image_write("Readme_files/figure-gfm/plot-full-bar-stack-painted.png")
)
```

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

### One last plot

@@ -280,13 +285,11 @@ ridges_pomological <- ggplot(diamonds) +
scale_fill_pomological() +
scale_color_pomological()

paint_pomological(ridges_pomological, res = 110) %>%
magick::image_write("Readme_files/figure-gfm/plot-ridges-painted.png")
paint_pomological(ridges_pomological, res = 110)
#> Picking joint bandwidth of 0.057
```

## Picking joint bandwidth of 0.057

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

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

binární
Readme_files/figure-gfm/ggpomological-1.png Zobrazit soubor

Před Za
Šířka: 800  |  Výška: 500  |  Velikost: 569KB

binární
Readme_files/figure-gfm/ggpomological.png Zobrazit soubor

Před Za
Šířka: 800  |  Výška: 500  |  Velikost: 566KB

binární
Readme_files/figure-gfm/plot-bar-chart-1.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 43KB Šířka: 800  |  Výška: 500  |  Velikost: 537KB

binární
Readme_files/figure-gfm/plot-bar-chart-2.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 43KB

binární
Readme_files/figure-gfm/plot-bar-chart-painted.png Zobrazit soubor

Před Za
Šířka: 800  |  Výška: 500  |  Velikost: 537KB

binární
Readme_files/figure-gfm/plot-demo-1.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 48KB Šířka: 800  |  Výška: 500  |  Velikost: 538KB

binární
Readme_files/figure-gfm/plot-demo-2.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 48KB Šířka: 768  |  Výška: 480  |  Velikost: 48KB

binární
Readme_files/figure-gfm/plot-demo-3.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 43KB Šířka: 768  |  Výška: 480  |  Velikost: 48KB

binární
Readme_files/figure-gfm/plot-demo-4.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 43KB Šířka: 768  |  Výška: 480  |  Velikost: 43KB

binární
Readme_files/figure-gfm/plot-demo-painted.png Zobrazit soubor

Před Za
Šířka: 800  |  Výška: 500  |  Velikost: 538KB

binární
Readme_files/figure-gfm/plot-density-1.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 50KB Šířka: 800  |  Výška: 500  |  Velikost: 518KB

binární
Readme_files/figure-gfm/plot-density-2.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 50KB

binární
Readme_files/figure-gfm/plot-density-demo-painted.png Zobrazit soubor

Před Za
Šířka: 800  |  Výška: 500  |  Velikost: 518KB

binární
Readme_files/figure-gfm/plot-full-bar-stack-1.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 52KB Šířka: 800  |  Výška: 500  |  Velikost: 523KB

binární
Readme_files/figure-gfm/plot-full-bar-stack-2.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 52KB

binární
Readme_files/figure-gfm/plot-full-bar-stack-painted.png Zobrazit soubor

Před Za
Šířka: 800  |  Výška: 500  |  Velikost: 523KB

binární
Readme_files/figure-gfm/plot-points-lines-1.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 59KB

binární
Readme_files/figure-gfm/plot-ridges-painted.png → Readme_files/figure-gfm/plot-ridges-1.png Zobrazit soubor

Před Za
Šířka: 800  |  Výška: 500  |  Velikost: 528KB Šířka: 800  |  Výška: 500  |  Velikost: 528KB

binární
Readme_files/figure-gfm/unnamed-chunk-1-1.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 25KB

binární
Readme_files/figure-gfm/unnamed-chunk-1-2.png Zobrazit soubor

Před Za
Šířka: 768  |  Výška: 480  |  Velikost: 22KB Šířka: 768  |  Výška: 480  |  Velikost: 25KB

binární
Readme_files/pom-examples.jpg Zobrazit soubor

Před Za
Šířka: 2301  |  Výška: 1350  |  Velikost: 3.2MB Šířka: 900  |  Výška: 528  |  Velikost: 614KB

+ 1
- 0
pomological.Rproj Zobrazit soubor

@@ -15,3 +15,4 @@ LaTeX: pdfLaTeX
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,namespace,vignette

+ 2
- 0
vignettes/.gitignore Zobrazit soubor

@@ -0,0 +1,2 @@
*.html
*.R

+ 241
- 0
vignettes/ggpomological.Rmd Zobrazit soubor

@@ -0,0 +1,241 @@
---
title: "ggpomological"
author: "Garrick Aden-Buie"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{ggpomological}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
knitr::opts_chunk$set(echo = TRUE, fig.width=8, fig.height=5)
library(ggpomological)
library(dplyr)
```

<!-- Links -->
[rstudioconf]: https://www.rstudio.com/conference/
[t-aronatkins]: https://twitter.com/aronatkins
[rsconf-slides]: https://github.com/rstudio/rstudio-conf/tree/master/2018/Fruit_For_Thought--Aron_Atkins
[rsconf-video]: https://youtu.be/Ol1FjFR2IMU?t=5h21m15s
[usda-pom]: https://usdawatercolors.nal.usda.gov/pom
[t-pomological]: https://twitter.com/pomological
[magick]: https://cran.r-project.org/web/packages/magick/index.html

This package provides a ggplot2 theme inspired by the [USDA Pomological Watercolors collection][usda-pom] and by Aron Atkins's ([&commat;aronatkins][t-aronatkins]) [talk on parameterized RMarkdown][rsconf-video] at [rstudio::conf 2018][rstudioconf].

```{r ggpomological, echo=FALSE, message=FALSE, warning=FALSE}
fruits <- c("Apple", "Apricot", "Banana", "Fig", "Cherry", "Kiwi", "Grape", "Mango", "Papaya", "Orange", "Peach", "Pear")
readr::read_tsv("https://cs.joensuu.fi/sipu/datasets/Compound.txt", col_names = FALSE) %>%
filter(X3 < 10) %>%
mutate(X3 = sample(fruits, length(unique(X3)))[X3]) %>%
{
ggplot(., aes(x = X1, y = X2, color = X3)) +
geom_point() +
labs(x = "Space", y = "Time",
color = "Fruit", title = "ggpomological") +
scale_color_pomological() +
theme_pomological_fancy()
} %>%
paint_pomological(res = 110)
```

`r knitr::include_graphics(here::here("Readme_files/pom-examples.jpg"))`^[U.S. Department of Agriculture Pomological Watercolor Collection. Rare and Special Collections, National Agricultural Library, Beltsville, MD 20705]

## Color Palette

The colors for this theme were drawn from many images from the [USDA Pomological Watercolors collection][usda-pom], I chose just a few that I thought worked well together for color and fill scales

```{r}
scales::show_col(ggpomological:::pomological_palette)
```

and a few colors for the plot background and decoration

```{r}
scales::show_col(unlist(ggpomological:::pomological_base))
```

I've also included a [css file](inst/pomological.css) with the complete collection of color samples.


## Setup theme and scales

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_plain()` has the same styling, just with a transparent (or white) background,

- `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.

- [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!

**ggpomological** also provides a function named `paint_pomological` that uses the [`magick`][magick] package to add a pomological watercolor paper background and a subtle texture overlay.


## Demo!

We'll need ggplot2 (loaded with **ggpomological**) and dplyr

```r
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}
# Base plot
basic_iris_plot <- ggplot(iris) +
aes(x = Sepal.Length, y = Sepal.Width, color = Species) +
geom_point(size = 2)

# Just your standard Iris plot
basic_iris_plot

# With pomological colors
basic_iris_plot <- basic_iris_plot + scale_color_pomological()
basic_iris_plot

# With pomological theme
basic_iris_plot + theme_pomological()

# With transparent background
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)
```


### Stacked bar chart


```{r plot-bar-chart}
stacked_bar_plot <- ggplot(diamonds) +
aes(price, fill = cut) +
geom_histogram(binwidth = 850) +
xlab('Price (USD)') +
ylab('Count') +
ggtitle("ggpomological") +
scale_x_continuous(label = scales::dollar_format()) +
scale_fill_pomological()

stacked_bar_plot + theme_pomological("Homemade Apple", 16)

paint_pomological(
stacked_bar_plot + theme_pomological_fancy(),
res = 110
)
```

### Density Plot

```{r plot-density}
density_plot <- mtcars %>%
mutate(cyl = factor(cyl)) %>%
ggplot() +
aes(mpg, fill = cyl, color = cyl)+
geom_density(alpha = 0.75) +
labs(fill = 'Cylinders', colour = 'Cylinders', x = 'MPG', y = 'Density') +
scale_color_pomological() +
scale_fill_pomological()

density_plot + theme_pomological("Homemade Apple", 16)

paint_pomological(
density_plot + theme_pomological_fancy(),
res = 110
)
```


### Points and lines

Data from the Texas Housing

```{r plot-full-bar-stack}
big_volume_cities <- txhousing %>%
group_by(city) %>%
summarize(mean_volume = mean(volume, na.rm = TRUE)) %>%
arrange(-mean_volume) %>%
top_n(length(ggpomological:::pomological_palette)) %>%
pull(city)

full_bar_stack_plot <- txhousing %>%
filter(city %in% big_volume_cities) %>%
group_by(city, year) %>%
summarize(mean_volume = mean(volume, na.rm = TRUE)) %>%
ungroup %>%
mutate(city = factor(city, big_volume_cities)) %>%
ggplot() +
aes(year, mean_volume, fill = city, group = city) +
geom_col(position = 'fill', width = 0.9) +
labs(x = 'City', y = 'Mean Volume', color = 'City') +
theme(panel.grid.minor.x = element_blank()) +
scale_fill_pomological()

full_bar_stack_plot + theme_pomological("Homemade Apple", 16)

paint_pomological(
full_bar_stack_plot + theme_pomological_fancy(),
res = 110
)
```

### One last plot

Using my own handwriting and the `ggridges` package.

```{r plot-ridges}
ridges_pomological <- ggplot(diamonds) +
aes(x = carat, y = clarity, color = clarity, fill = clarity) +
ggridges::geom_density_ridges(alpha = 0.75) +
theme_pomological(
base_family = 'gWriting',
base_size = 20,
base_theme = ggridges::theme_ridges()
) +
scale_fill_pomological() +
scale_color_pomological()

paint_pomological(ridges_pomological, res = 110)
```


Načítá se…
Zrušit
Uložit