sequential_layer_facets: Change facet ordering behaviour

View source: R/ggstrat-plot_addons.R

sequential_layer_facetsR Documentation

Change facet ordering behaviour

Description

Normally, facets are ordered using as.factor on all values that occur within layer data, which means that when adding additional layers, any ordering is not preserved unless the factor levels are identical on all factors. This function changes this behaviour such that facet levels are combined in layer order. This is useful when adding standalone layers to a plot without disturbing the existing order.

Usage

sequential_layer_facets(reverse = FALSE)

Arguments

reverse

Use TRUE to process layers in reverse order

Value

An object that can be added to a ggplot2::ggplot()

Examples

library(ggplot2)

p <- ggplot(mapping = aes(x, y)) +
  geom_point(data = data.frame(x = 1:5, y = 1:5, facet = "b")) +
  geom_point(data = data.frame(x = 1:5, y = 1:5, facet = "a")) +
  facet_wrap(vars(facet))

p
p + sequential_layer_facets()


paleolimbot/tidypaleo documentation built on Jan. 25, 2023, 2:43 a.m.