
<!-- README.md is generated from README.Rmd. Please edit that file -->

# ggrefine <a href="https://davidhodge931.github.io/ggrefine/"><img src="man/figures/logo.png" align="right" height="139" alt="ggrefine website" /></a>

<!-- badges: start -->

[![CRAN
status](https://www.r-pkg.org/badges/version/ggrefine)](https://CRAN.R-project.org/package=ggrefine)
<!-- badges: end -->

The objective of ggrefine is to provide complete themes for
publication-quality ‘ggplot2’ visualisation. Functions are provided to
modify these based on the positional axis scales and orientation of a
particular plot.

## Installation

Install from CRAN, or development version from
[GitHub](https://github.com/).

``` r
install.packages("ggrefine") 
pak::pak("davidhodge931/ggrefine")
```

## Theme

The themes are built to work with the refine functions in that they have
all axis and panel grid elements.

They can also be customised easily.

The `theme_grey` function has a smart `panel_grid_colour` default that
is derived from the `panel_background_fill`.

To ensure ggrefine `theme_*` functions are preferred over ggplot2
functions:

- run `library(ggrefine)` after the ggplot2 library is loaded, or
- use `conflicted::conflict_prefer_all(winner = "ggrefine")`, or
- do not load ggrefine, but instead use `ggrefine::theme_grey()` etc.

``` r
library(ggplot2)
library(ggrefine)

p_base_light <- mpg |>
  ggplot(aes(x = hwy)) +
  geom_histogram(
    stat = "bin", shape = 21,
    colour = blends::multiply("#357BA2FF")
  ) +
  scale_y_continuous(expand = expansion(mult = c(0, 0.05)))

p_base_dark <- mpg |>
  ggplot(aes(x = hwy)) +
  geom_histogram(
    stat = "bin", shape = 21,
    colour = blends::screen("#357BA2FF")
  ) +
  scale_y_continuous(expand = expansion(mult = c(0, 0.05)))

p_light  <- p_base_light + theme_light() + labs(title = "theme_light")
p_dark  <- p_base_dark  + theme_dark() + labs(title = "theme_dark")
p_grey <- p_base_light + theme_grey() + labs(title = "theme_grey")
p_ggplot2 <- p_base_light + theme_grey(panel_grid_colour = "white") + 
  labs(title = "theme_ggplot")

patchwork::wrap_plots(
  p_light,
  p_dark,
  p_grey,
  p_ggplot2
)
```

<img src="man/figures/README-example-1.png" alt="" width="100%" />

## Refine

A series of refine functions are provided.

The premise is that it is useful to set themes that have all axis and
panel grid elements - and then adjust depending on the positional axis
scales and orientation of a particular plot.

The refine functions are organised and named by:

- axis: `classic_*`, `modern_*`, `minimal_*`, and `void_*`.
- panel grid: `*_drift`, `*_flow`, `*_drop`, `*_keep`.

These functions then remove or not particular axis and panel grid
components for different positional scales (and the intended orientation
of the plot).

``` r
set_theme(new = theme_light(
  panel_grid_colour = jumble::grey,
  axis_line_colour = jumble::red,
))

p_continuous <- mpg |>
  ggplot(aes(x = displ, y = hwy)) +
  geom_point(shape = 21, colour = blends::multiply("#357BA2FF"))

p_discrete_x <- mpg |>
  ggplot(aes(x = drv, y = hwy)) +
  geom_jitter(shape = 21, colour = blends::multiply("#357BA2FF"))

p_discrete_y <- mpg |>
  ggplot(aes(x = hwy, y = drv)) +
  geom_jitter(shape = 21, colour = blends::multiply("#357BA2FF"))
```

``` r
patchwork::wrap_plots(
  p_continuous + classic_drift() + labs(title = "classic_drift"),
  p_discrete_x + classic_drift(discrete = "x"),
  p_discrete_y + classic_drift(discrete = "y"),

  p_continuous + classic_flow() + labs(title = "classic_flow"),
  p_discrete_x + classic_flow(discrete = "x"),
  p_discrete_y + classic_flow(discrete = "y"),

  p_continuous + classic_drop() + labs(title = "classic_drop"),
  p_discrete_x + classic_drop(discrete = "x"),
  p_discrete_y + classic_drop(discrete = "y"),
  
  p_continuous + classic_keep() + labs(title = "classic_keep"),
  p_discrete_x + classic_keep(discrete = "x"),
  p_discrete_y + classic_keep(discrete = "y"),

  ncol = 3
)
```

<img src="man/figures/README-unnamed-chunk-3-1.png" alt="" width="100%" />

``` r
patchwork::wrap_plots(
  p_continuous + modern_drift() + labs(title = "modern_drift"),
  p_discrete_x + modern_drift(discrete = "x"),
  p_discrete_y + modern_drift(discrete = "y"),

  p_continuous + modern_flow() + labs(title = "modern_flow"),
  p_discrete_x + modern_flow(discrete = "x"),
  p_discrete_y + modern_flow(discrete = "y"),

  p_continuous + modern_drop() + labs(title = "modern_drop"),
  p_discrete_x + modern_drop(discrete = "x"),
  p_discrete_y + modern_drop(discrete = "y"),

  p_continuous + modern_keep() + labs(title = "modern_keep"),
  p_discrete_x + modern_keep(discrete = "x"),
  p_discrete_y + modern_keep(discrete = "y"),

  ncol = 3
)
```

<img src="man/figures/README-unnamed-chunk-4-1.png" alt="" width="100%" />

``` r
patchwork::wrap_plots(
  p_continuous + minimal_drift() + labs(title = "minimal_drift"),
  p_discrete_x + minimal_drift(discrete = "x"),
  p_discrete_y + minimal_drift(discrete = "y"),

  p_continuous + minimal_flow() + labs(title = "minimal_flow"),
  p_discrete_x + minimal_flow(discrete = "x"),
  p_discrete_y + minimal_flow(discrete = "y"),

  p_continuous + minimal_drop() + labs(title = "minimal_drop"),
  p_discrete_x + minimal_drop(discrete = "x"),
  p_discrete_y + minimal_drop(discrete = "y"),
  
  p_continuous + minimal_keep() + labs(title = "minimal_keep"),
  p_discrete_x + minimal_keep(discrete = "x"),
  p_discrete_y + minimal_keep(discrete = "y"),

  ncol = 3
)
```

<img src="man/figures/README-unnamed-chunk-5-1.png" alt="" width="100%" />

``` r
patchwork::wrap_plots(
  p_continuous + void_drift() + labs(title = "void_drift"),
  p_discrete_x + void_drift(discrete = "x"),
  p_discrete_y + void_drift(discrete = "y"),

  p_continuous + void_flow() + labs(title = "void_flow"),
  p_discrete_x + void_flow(discrete = "x"),
  p_discrete_y + void_flow(discrete = "y"),

  p_continuous + void_drop() + labs(title = "void_drop"),
  p_discrete_x + void_drop(discrete = "x"),
  p_discrete_y + void_drop(discrete = "y"),
  
  p_continuous + void_keep() + labs(title = "void_keep"),
  p_discrete_x + void_keep(discrete = "x"),
  p_discrete_y + void_keep(discrete = "y"),

  ncol = 3
)
```

<img src="man/figures/README-unnamed-chunk-6-1.png" alt="" width="100%" />

## Other packages

This package is part of a group of related packages built to extend
[ggplot2](https://ggplot2.tidyverse.org).

<table>

<tr>

<td align="center">

<a href="https://davidhodge931.github.io/ggblanket/"><img src="https://raw.githubusercontent.com/davidhodge931/ggblanket/main/man/figures/logo.svg" width="120" alt="ggblanket"/></a>
</td>

<td align="center">

<a href="https://davidhodge931.github.io/ggrefine/"><img src="https://raw.githubusercontent.com/davidhodge931/ggrefine/main/man/figures/logo.svg" width="120" alt="ggrefine"/></a>
</td>

<td align="center">

<a href="https://davidhodge931.github.io/ggscribe/"><img src="https://raw.githubusercontent.com/davidhodge931/ggscribe/main/man/figures/logo.svg" width="120" alt="ggscribe"/></a>
</td>

<td align="center">

<a href="https://davidhodge931.github.io/ggwidth/"><img src="https://raw.githubusercontent.com/davidhodge931/ggwidth/main/man/figures/logo.svg" width="120" alt="ggwidth"/></a>
</td>

<td align="center">

<a href="https://davidhodge931.github.io/blends/"><img src="https://raw.githubusercontent.com/davidhodge931/blends/main/man/figures/logo.svg" width="120" alt="blends"/></a>
</td>

<td align="center">

<a href="https://davidhodge931.github.io/jumble/"><img src="https://raw.githubusercontent.com/davidhodge931/jumble/main/man/figures/logo.svg" width="120" alt="jumble"/></a>
</td>

</tr>

</table>
