Skip to contents

This function annotates the chart with the last date where data is available. It does so by looking by first filtering out missing values in the y-axis variable and then computing for these rows the maximum of the x-axis variable.

Usage

annotate_last_date(
  font_family = getOption("fedplot.font_family"),
  font_size = getOption("fedplot.font_size") * 7L/8L,
  color = "black",
  nudge_x = 0,
  nudge_y = 0,
  hjust = 0.5,
  repel = FALSE,
  box.padding = 0.25,
  point.padding = 1e-06,
  min.segment.length = 0.5,
  arrow = NULL,
  force = 1,
  force_pull = 1,
  max.time = 0.5,
  max.iter = 10000,
  max.overlaps = getOption("ggrepel.max.overlaps", default = 10),
  xlim = c(NA, NA),
  ylim = c(NA, NA),
  direction = c("both", "y", "x"),
  seed = 1234,
  verbose = FALSE,
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE,
  text_aes = NULL,
  ...
)

Arguments

font_family

Font family. If empty, it will default to Franklin Gothic Condensed (unless the "fedplot.font_family" option is overwritten).

font_size

Font size. If empty, will default to size 7 (unless the "fedplot.font_size" option is overwritten).

color

Color of the text. Defaults to black.

nudge_x

Manually nudge the x-axis of the text. Alternative to the repel option.

nudge_y

Manually nudge the y-axis of the text. Alternative to the repel option.

hjust

Horizontal justification; range is 0 to 1; default is 0.5 (centered).

repel

If set to TRUE, will try to reposition the text label to avoid overlapping it with other elements of the plot (such as the lines). It relies on the ggrepel::geom_text_repel() function of the ggrepel package.

box.padding

Amount of padding around bounding box, as unit or number. Defaults to 0.25. (Default unit is lines, but other units can be specified by passing unit(x, "units")).

point.padding

Amount of padding around labeled point, as unit or number. Defaults to 0. (Default unit is lines, but other units can be specified by passing unit(x, "units")).

min.segment.length

Skip drawing segments shorter than this, as unit or number. Defaults to 0.5. (Default unit is lines, but other units can be specified by passing unit(x, "units")).

arrow

specification for arrow heads, as created by arrow

force

Force of repulsion between overlapping text labels. Defaults to 1.

force_pull

Force of attraction between a text label and its corresponding data point. Defaults to 1.

max.time

Maximum number of seconds to try to resolve overlaps. Defaults to 0.5.

max.iter

Maximum number of iterations to try to resolve overlaps. Defaults to 10000.

max.overlaps

Exclude text labels that overlap too many things. Defaults to 10.

xlim, ylim

Limits for the x and y axes. Text labels will be constrained to these limits. By default, text labels are constrained to the entire plot area.

direction

"both", "x", or "y" -- direction in which to adjust position of labels

seed

Random seed passed to set.seed. Defaults to NA, which means that set.seed will not be called.

verbose

If TRUE, some diagnostics of the repel algorithm are printed

mapping

Set of aesthetic mappings created by aes or aes_. If specified and inherit.aes = TRUE (the default), is combined with the default mapping at the top level of the plot. You only need to supply mapping if there isn't a mapping defined for the plot.

data

A data frame. If specified, overrides the default data frame defined at the top level of the plot.

stat

The statistical transformation to use on the data for this layer, as a string.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

na.rm

If FALSE (the default), removes missing values with a warning. If TRUE silently removes missing values.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders.

text_aes

Named list, additional aesthetics to send to the geometry.

...

other arguments passed on to layer. There are three types of arguments you can use here:

  • Aesthetics: to set an aesthetic to a fixed value, like colour = "red" or size = 3.

  • Other arguments to the layer, for example you override the default stat associated with the layer.

  • Other arguments passed on to the stat.

Details

This function formats the last date string accordingly to its frequency and to publication standards. For instance, monthly data gets formatted as "Jan.", "Feb.", etc. with the exception of June and September that appear as "June" and "Sept." respectively.

Note that this formatting is currently incomplete for frequencies other than monthly.