djpr_ts_linechart: Create a standard time series linechart with DJPR...

View source: R/djpr_ts_linechart.R

djpr_ts_linechartR Documentation

Create a standard time series linechart with DJPR characteristics

Description

Create a standard time series linechart with DJPR characteristics

Usage

djpr_ts_linechart(
  data,
  y_var = .data$value,
  col_var = .data$series,
  group_var = NULL,
  dot = TRUE,
  label = TRUE,
  label_num = round2(.data$value, 1),
  y_labels = ggplot2::waiver(),
  hline = NULL,
  n_x_breaks = 5,
  x_expand_mult = c(0, 0.18),
  label_single_line = FALSE,
  label_wrap_length = 10
)

Arguments

data

A dataframe containing time series data. Your dataframe is presumed to include, at a minimum:

  • "date""A date column, of class "Date"

  • "value""A value column, of class numeric, containing data to be shown on the y-axis

  • "col_var""A variable to map to colour, which can be specified with the col_var argument."

y_var

Variable in data to map to the y aesthetic; default is value.

col_var

Variable in data to map to the colour aesthetic; default is series.

group_var

Variable in data to map to the group aesthetic; default is whatever is supplied to col_var

dot

Logical; TRUE by default. When TRUE, a filled dot will be shown on the most recent data point.

label

Logical; TRUE by default. When TRUE, a text label will be added to the right of the most recent data point.

label_num

Variable name (or expression) defining the label to be placed on the chart. Default is round2(value, 1). Ignored if label is FALSE.

y_labels

Supplied to the labels argument of ggplot2::scale_y_continuous()

hline

Numeric. If non-NULL (the default), a horizontal line will be drawn at the data value given. eg. if hline = 0, a geom_hline() will be added at y = 0.

n_x_breaks

Number of 'pretty' breaks on the x (date) axis. Passed to scales::breaks_pretty().

x_expand_mult

Length one or two numeric vector of padding to be added to the horizontal axis; passed to the expand argument of scale_x_date

label_single_line

Logical. FALSE by default. When true, a full label will be added to lines - even when only one line is present.

label_wrap_length

Numeric. The number of characters on each line of the label. Default is 10 characters.

Details

If a column called 'tooltip' is present, it will be used as the ggiraph tooltip; if not, one will be created.

Value

A ggplot2 object

Examples

## Not run: 
library(dplyr)
library(ggplot2)

data <- ggplot2::economics_long

data <- data %>%
  dplyr::rename(series = variable)

djpr_ts_linechart(data = data)

## End(Not run)


djpr-data/djprshiny documentation built on May 14, 2023, 1:15 p.m.