Learn R Programming

brfinance (version 0.8.0)

plot_series_comparison: Compare multiple financial/time series indices

Description

Plots multiple time series on the same chart for comparison.

Usage

plot_series_comparison(
  data_list,
  y_vars,
  date_vars,
  language = "eng",
  scale_type = c("none", "index", "percent_change"),
  title = NULL,
  subtitle = NULL,
  y_label = NULL,
  caption = NULL,
  colors = NULL,
  line_types = NULL,
  show_legend = TRUE,
  legend_position = "bottom"
)

Value

A ggplot2 object

Arguments

data_list

Named list of data frames, each returned by a get_* function

y_vars

Vector of column names containing the values to plot from each data frame

date_vars

Vector of column names containing dates from each data frame

language

Language for labels: "pt" (Portuguese) or "eng" (English)

scale_type

Scaling applied to the series:

"none"

Plots raw values as provided

"index"

Indexes all series to 100 at the first observation

"percent_change"

Plots percentage change relative to the first observation

title

Plot title

subtitle

Plot subtitle

y_label

Y-axis label

caption

Plot caption

colors

Vector of colors for each series

line_types

Vector of line types for each series

show_legend

Whether to show the legend (default: TRUE)

legend_position

Position of legend ("bottom", "top", "left", "right", or "none")

Examples

Run this code
if (FALSE) { # interactive()
# Example comparing multiple series
selic <- get_selic_rate(2020, 2024)
ipca <- get_ipca(2020, 2024)
igpm <- get_igpm(2020, 2024)

comparison_plot <- plot_series_comparison(
  data_list = list(SELIC = selic, IPCA = ipca, IGPM = igpm),
  y_vars = c("value", "value", "value"),
  date_vars = c("date", "date", "date"),
  scale_type = "index",
  title = "Comparison of Brazilian Economic Indicators",
  y_label = "Index (2020-01 = 100)",
  language = "eng"
)
print(comparison_plot)
}

Run the code above in your browser using DataLab