Skip to contents

Create time series plots optimized for economic/business data using Insper's visual identity. Automatically handles Date and POSIXct x-axis variables and supports both discrete and continuous color mappings.

Usage

insper_timeseries(
  data,
  x,
  y,
  color = NULL,
  palette = "categorical",
  line_width = 0.8,
  add_points = FALSE,
  ...
)

Arguments

data

A data frame containing the data to plot

x

Time variable (numeric, Date, or POSIXct)

y

Value variable

color

Color aesthetic for multiple lines. Accepts either:

  • A bare column name for variable mapping (e.g., color = category)

  • A quoted color string for static color (e.g., color = "blue")

  • NULL (default) to use default Insper teal

When mapping a variable, the appropriate scale is automatically applied.

palette

Character. Color palette for variable mappings. Default is "categorical".

line_width

Numeric. Width of lines. Default is 0.8

add_points

Logical. If TRUE, adds points to lines. Default is FALSE

...

Additional arguments passed to ggplot2::geom_line(), allowing custom aesthetics like linetype, alpha, etc.

Value

A ggplot2 object

Examples

if (FALSE) { # has_insper_fonts()
library(ggplot2)

# Plot inflation over time
insper_timeseries(macro_series, x = date, y = ipca)

# The color argument automatically detects the type of variable
insper_timeseries(macro_series, x = date, y = ipca, color = "#3CBFAE")

# Grouped time series (discrete variable)
recent_data <- subset(fossil_fuel, year >= 1920)
insper_timeseries(recent_data, x = year, y = consumption, color = fuel)
}