sankey_ly: Sankey Plot with Plotly

View source: R/dataviz.R

sankey_lyR Documentation

Sankey Plot with Plotly

Description

Sankey Plot with Plotly

Usage

sankey_ly(x, cat_cols, num_col, title = NULL)

Arguments

x

A data.frame input, must have at least two categorical columns and one numeric column

cat_cols

A vector of at least two categorical columns names

num_col

A single numeric column name

title

Optional, string to pass to plotly layout title function

Details

A customized function for data transformation and plotting sankey plot with Plotly

Examples

data("sfo_passengers")

library(dplyr)

d <- sfo_passengers %>%
  filter(activity_period >= 202201 & activity_period < 202301)

head(d)

d %>%
  filter(operating_airline == "United Airlines") %>%
  mutate(terminal = ifelse(terminal == "International", "international", terminal)) %>%
  group_by(operating_airline,activity_type_code, geo_summary, geo_region,  terminal) %>%
  summarise(total = sum(passenger_count), .groups = "drop") %>%
  sankey_ly(cat_cols = c("operating_airline", "terminal","geo_summary",
                         "geo_region", "activity_type_code"),
            num_col = "total",
            title = "Distribution of United Airlines Passengers at SFO During 2022")

sfo documentation built on March 31, 2023, 8:32 p.m.