ptt_plot_add_secondary_traces2: Add secondary traces of existing traces with reduced...

View source: R/ptt_plot_extra.R

ptt_plot_add_secondary_traces2R Documentation

Add secondary traces of existing traces with reduced linewidth to an existing ptt_plot.

Description

Outputs a plotly object.

Usage

ptt_plot_add_secondary_traces2(
  p,
  secondary_data,
  y = value,
  grouping,
  name = NULL,
  line_width = 2,
  hovertext,
  showlegend = FALSE,
  grouplegend = TRUE
)

Arguments

p

Plotly object created with ptt_plot to add prediction traces to.

secondary_data

Tibble with secondary variables of one grouping in the parent ptt_plot object.

grouping

Tibble column used for grouping in plot, should be labeled the same as data used for parent ptt_plot.

name

The name of the data in the secondary data.

line_width

A width of the line.

hovertext

Uses parent ptt_plot specification if undefined. A list describing hovertext items "list(rounding = 1, unit = "%", extra = "(ennuste)", dateformat = "%Y-%m-&d")".

showlegend

A locigal to show legend for secondary trace.

grouplegend

A locigal to tie legend grouping to grouping in p.

Value

plotly object

Examples

library(tidyverse)
library(pttdatahaku)
dat <- ptt_data_robo("StatFin/ntp/statfin_ntp_pxt_132h.px") |>
  filter_recode(
    taloustoimi = c(
      "BKT" = "B1GMH Bruttokansantuote markkinahintaan",
      "Vienti" = "P61K Tavaroiden vienti, menona"),
    tiedot = c(
     kausitasoitettu = "Kausitasoitetun ja työpäiväkorjatun sarjan volyymin muutos vuodentakaisesta, %",
     trendi = "Trendisarjan volyymin muutos vuodentakaisesta, %")) |>
 spread(tiedot, value)
dat |>
  rename(value = trendi) |>
  ptt_plot(grouping = taloustoimi,
           title = "BKT ja vienti",
           subtitle = "%, volyymin vuosimuutos",
           caption = "Lähde: Tilastokeskus, PTT") |>
  ptt_plot_add_secondary_traces2(dat, y = kausitasoitettu, grouping = taloustoimi)

  dat |>
  rename(value = trendi) |>
  ptt_plot(grouping = taloustoimi,
           title = "BKT ja vienti",
           subtitle = "%, volyymin vuosimuutos, trendi ja kausitasoitettu",
           caption = "Lähde: Tilastokeskus, PTT") |>
  ptt_plot_add_secondary_traces2(dat, y = kausitasoitettu, grouping = taloustoimi,
  name = "kausitasoitettu", showlegend = TRUE, grouplegend = FALSE)

pttry/pttrobo documentation built on March 5, 2025, 6:36 p.m.