Title: Geoms for Playfair-Style Charts
Version: 0.1.1
Description: Currently provides geom_balance_of_trade(), a 'ggplot2' layer that fills the area between exports and imports series (with automatic crossing detection and conditional coloring for surplus vs. deficit), and overlays lines and points by default.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: ggplot2 (≥ 3.4.0)
Suggests: testthat (≥ 3.0.0), roxygen2 (≥ 7.1.0),
RoxygenNote: 7.3.2
URL: https://github.com/DerekStevens99/ggplayfair
BugReports: https://github.com/DerekStevens99/ggplayfair/issues
Maintainer: Derek Stevens <derekburgandy@gmail.com>
NeedsCompilation: no
Packaged: 2025-07-24 23:43:32 UTC; derek
Author: Derek Stevens [aut, cre]
Repository: CRAN
Date/Publication: 2025-07-28 18:30:02 UTC

GeomBalanceOfTrade

Description

A ribbon between exports and imports, automatically coloring surplus vs deficit.

Usage

GeomBalanceOfTrade

Format

An object of class GeomBalanceOfTrade (inherits from GeomRibbon, Geom, ggproto, gg) of length 3.


StatBalanceOfTrade

Description

Splits a time series of exports and imports into segments of trade surplus or deficit, inserting interpolated intersection points where they cross. This allows ribbons to be shaded differently for surplus vs deficit in a balance of trade plot.

Usage

StatBalanceOfTrade

Format

An object of class StatBalanceOfTrade (inherits from Stat, ggproto, gg) of length 4.

Details

A ggplot2::Stat that computes ribbon boundaries for trade balance visualization. It takes export and import values and generates ymin/ymax pairs for plotting shaded ribbons showing surplus or deficit. Used internally by geom_balance_of_trade().

Value

A data.frame with columns: x, ymin, ymax, direction, and group. These are passed to a GeomRibbon layer to visualize the balance of trade.

See Also

geom_balance_of_trade()


geom_balance_of_trade

Description

geom_balance_of_trade() creates a custom ggplot2 ribbon that visualizes the balance of trade by shading the area between exports and imports.

Usage

geom_balance_of_trade(
  data = NULL,
  mapping = NULL,
  stat = StatBalanceOfTrade,
  geom = GeomBalanceOfTrade,
  position = "identity",
  ...,
  na.rm = FALSE,
  show.legend = NA
)

Arguments

data

A data frame (defaults to the plot-level data)

mapping

Set of aesthetic mappings, see geom_ribbon

stat

Stat to use (defaults to StatBalanceOfTrade)

geom

Geom to use (defaults to GeomBalanceOfTrade)

position

Position adjustment

...

Other arguments passed on to the layer (e.g. na.rm)

na.rm

If TRUE, remove NAs

show.legend

Should this layer be included in the legend?

Value

A ggplot2 layer representing the balance of trade. Within the layer with be a colored ribbon and two lines and point sets representing your imports and exports

Note

If you map exports/imports in the global aes(), you'll see: \"The following aesthetics were dropped…exports and imports.\" This simply means the stat used them to compute the ribbon and then removed them—your plot still renders correctly. To suppress this warning, simply move the aes to the geom_balance_of_trade() call.