ptt_plot: Creates a plotly object with visual specifications of ptt.

View source: R/ptt_plot_base.R

ptt_plotR Documentation

Creates a plotly object with visual specifications of ptt.

Description

Outputs a plotly object.

Usage

ptt_plot(
  d,
  grouping,
  title,
  subtitle = "",
  caption,
  legend_orientation = "auto",
  legend_position = "bottom",
  margin = NA,
  font_color = "#696969",
  grid_color = "#E8E8E8",
  trace_color = NULL,
  highlight = NULL,
  zeroline = F,
  rangeslider = FALSE,
  line_width = 4,
  font_size = 14,
  hovertext,
  axis_limits = list(x = c(NA, NA), y = c(NA, NA)),
  plot_type = "scatter",
  plot_mode = "dodge",
  height = 550,
  facet_split,
  ...
)

Arguments

d

Data for plotting (Tibble).

grouping

Tibble column from tibble d to use for grouping (Unquoted string).

title, subtitle, caption

labeling for plot

legend_orientation, legend_position

Legend positioning.

margin

Plot margins if calculated margins do not work (List).

font_color, grid_color, font_size

Plot background element colors and font sizes.

trace_color

Trace color for all traces. Either a character string or a character vector of name-value pairs interpretable as colors (Character vector).

highlight

Either NULL, a double that limits, or a function that returns a logical determining if a given trace is included in legend and assigned a color.

zeroline

Determines zeroline inclusion (Logical or double).

rangeslider

Determines rangeslider inclusion (Logical).

line_width

Line width for line plots. Either a double or a double vector of name-value pairs (Double vector).

hovertext

A list describing hovertext items "list(rounding = 1, unit = "%", extra = "(ennuste)")".

axis_limits

Determines the limits of the axes (list(x = c(NA,NA), y = c(NA,NA)))".

plot_type

Determines the trace type for either the whole plot, or for all variables defined by grouping as name-value pairs (Character vector).

plot_mode

Determines the barmode for a barplot. Disregarded for scatterplots. (Character).

height

Height of the plot.

Value

plotly object

Examples

d <- ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
  dplyr::filter(stringr::str_detect(taloustoimi, "B1GMH|P3KS14_S15"), tiedot == "Kausitasoitettu ja työpäiväkorjattu sarja, viitevuosi 2015, miljoonaa euroa", lubridate::year(time) >= 2010) |>
  dplyr::group_by(taloustoimi) |>
  dplyr::mutate(value = ((value/ lag(value, 4)) -1) * 100) |>
  dplyr::ungroup() |>
  dplyr::mutate(tiedot = dplyr::case_when(stringr::str_detect(taloustoimi, "B1GMH") ~ "BKT", TRUE ~ "Yksityinen kulutus") |> forcats::as_factor()) |>
  tidyr::drop_na()
  p <- d |> ptt_plot(tiedot, "BKT ja kulutus", subtitle = "Vuosimuutos",
  caption =  "Lähde: Tilastokeskus ja PTT",
  rangeslider = "2015-01-01",
  zeroline = T)
  p

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