secondary_plot {ezplot}R Documentation

secondary_plot creates a plot with a secondary y-axis

Description

secondary_plot creates a plot with a secondary y-axis

Usage

secondary_plot(
  data,
  x,
  y1 = "1",
  y2 = "1",
  facet_x = NULL,
  facet_y = NULL,
  palette = ez_col,
  size_line = 1,
  labels_y1 = ez_labels,
  labels_y2 = ez_labels,
  ylim1 = NULL,
  ylim2 = NULL,
  reorder = c("facet_x", "facet_y"),
  size = 11
)

Arguments

data

A data.frame.

x

A named character value. Evaluates to a column.

y1

Variable to plot on the left-hand axis

y2

Variable to plot on the right-hand axis

facet_x

A character value. Evaluates to a column.

facet_y

A character. Evaluates to a column.

palette

Colour function.

size_line

line size

labels_y1

label formatting function

labels_y2

label formatting function

ylim1

(optional) left axis limits

ylim2

(optional) right axis limits

reorder

A character vector specifying the group variables to reorder. Default is c("group", "facet_x", "facet_y").

size

theme size for use_theme(). Default is 14.

Value

A ggplot object.

Examples

suppressPackageStartupMessages(library(tsibble))
library(tsibbledata)
secondary_plot(pelt, "Year", "Hare", "Lynx")
secondary_plot(pelt, "Year", c("Hare Population" = "Hare"), c("Lynx Population" = "Lynx"))
secondary_plot(aus_production, "Quarter",
               c("Quarterly Beer Production (megalitres)" = "Beer"),
               c("Quarterly Cement Production (tonnes)" = "Cement"),
               "lubridate::quarter(Quarter)",
               ylim1 = c(0, 600), ylim2 = c(0, 3000),
               size = 10)

[Package ezplot version 0.7.13 Index]