Skip to contents

When looking into data set with a date or datetime fields, narrator is exploring changes that happen to selected measure in time. Here is a glimpse of such a data set:

Year-over-Year

df <- sales %>%
  dplyr::mutate(Date = lubridate::floor_date(Date, unit = "month")) %>%
  dplyr::group_by(Region, Product, Date) %>%
  dplyr::summarise(Sales = sum(Sales, na.rm = TRUE))

df %>%
  head() %>%
  kable()
Region Product Date Sales
ASPAC Baby 2019-01-01 5838.30
ASPAC Baby 2019-02-01 2993.70
ASPAC Baby 2019-03-01 5783.30
ASPAC Baby 2019-04-01 2122.00
ASPAC Baby 2019-05-01 10770.98
ASPAC Baby 2019-06-01 546.60

Default narrative returned will be analyzing year-to-date (YTD) vs prior year-to-date (PYTD) volumes, based on the data set date range. So current year will be considered to be the max date of supplied data.

narrate_trend(df)
#> $`2021 YTD vs 2020 YTD`
#> From 2020 YTD to 2021 YTD, Sales had an increase of 1.13 M (9.1 %, 12.42 M to 13.55 M).
#> 
#> $`Sales change by Region`
#> Regions with biggest changes of Sales are NA (533.1 K, 9.1 %, 5.9 M to 6.4 M) and EMEA (416.9 K, 9.91 %, 4.2 M to 4.6 M).
#> 
#> $`NA by Product`
#> In NA, significant Products by Sales change are Food & Beverage (243.3 K, 9.92 %, 2.5 M to 2.7 M) and Tools (186.8 K, 31.87 %, 585.9 K to 772.7 K).
#> 
#> $`EMEA by Product`
#> In EMEA, significant Products by Sales change are Electronics (312.1 K, 35.88 %, 869.7 K to 1.2 M) and Food & Beverage (238.2 K, 14.54 %, 1.6 M to 1.9 M).
#> 
#> $`Sales change by Product`
#> Products with biggest changes of Sales are Food & Beverage (535.4 K, 10.63 %, 5 M to 5.6 M) and Electronics (525.9 K, 19.79 %, 2.7 M to 3.2 M).
#> 
#> $`Food & Beverage by Month`
#> In Food & Beverage, significant Months by Sales change are Oct (-141.6 K, -23.39 %, 605.4 K to 463.8 K), Sep (132.7 K, 37.27 %, 356.2 K to 489 K), Dec (118.3 K, 16.67 %, 709.5 K to 827.8 K) and May (99 K, 28.12 %, 352 K to 451 K).
#> 
#> $`Electronics by Month`
#> In Electronics, significant Months by Sales change are Nov (170.7 K, 70.62 %, 241.7 K to 412.4 K), Dec (108.3 K, 36.23 %, 298.8 K to 407.1 K), May (-74.1 K, -26.73 %, 277.3 K to 203.2 K) and Feb (70.6 K, 38.24 %, 184.6 K to 255.3 K).
#> 
#> $`Sales change by Month`
#> Months with biggest changes of Sales are Nov (386.5 K, 29.17 %, 1.3 M to 1.7 M), Apr (226.6 K, 24.4 %, 928.6 K to 1.2 M) and Jan (162.2 K, 23.06 %, 703.4 K to 865.6 K).

Previous Period

Different time frame can be selected using type argument of narrate_trend() function. Both numeric and string values are accepted, where 1 stands for ‘yoy’, 2 for ‘previous period’, 3 for ‘same period last year’.

When previous period is selected, we compare volumes from December 2021 to November 2021:

narrate_trend(df, type = "previous period")
#> $`Dec 2021 vs Nov 2021`
#> From Nov 2021 to Dec 2021, Sales had an increase of 176.32 K (10.3 %, 1.71 M to 1.89 M).
#> 
#> $`Sales change by Region`
#> Regions with biggest changes of Sales are EMEA (154.2 K, 26.54 %, 580.8 K to 735 K) and NA (-111 K, -13.14 %, 844.4 K to 733.4 K).
#> 
#> $`EMEA by Product`
#> In EMEA, significant Products by Sales change are Food & Beverage (97.1 K, 45.41 %, 213.8 K to 310.9 K) and Tools (60.1 K, 76.53 %, 78.6 K to 138.7 K).
#> 
#> $`NA by Product`
#> In NA, significant Products by Sales change are Tools (-87.2 K, -55.54 %, 157 K to 69.8 K) and Home (-51.4 K, -44.95 %, 114.3 K to 62.9 K).
#> 
#> $`Sales change by Product`
#> Product with biggest changes of Sales is Food & Beverage (197.2 K, 31.28 %, 630.6 K to 827.8 K).

Same Period Last Year

Alternatively, we can use numeric option, if you are more comfortable with it. Here the function will get December 2020 data for comparison:

narrate_trend(df, type = 3)
#> $`Dec 2021 vs Dec 2020`
#> From Dec 2020 to Dec 2021, Sales had an increase of 92.89 K (5.2 %, 1.79 M to 1.89 M).
#> 
#> $`Sales change by Region`
#> Regions with biggest changes of Sales are EMEA (184.3 K, 33.48 %, 550.6 K to 735 K) and NA (-144.3 K, -16.44 %, 877.8 K to 733.4 K).
#> 
#> $`EMEA by Product`
#> In EMEA, significant Products by Sales change are Food & Beverage (104.2 K, 50.43 %, 206.7 K to 310.9 K) and Tools (78.5 K, 130.46 %, 60.2 K to 138.7 K).
#> 
#> $`NA by Product`
#> In NA, significant Products by Sales change are Clothing (-71.6 K, -76.95 %, 93.1 K to 21.5 K) and Home (-44.3 K, -41.31 %, 107.2 K to 62.9 K).
#> 
#> $`Sales change by Product`
#> Products with biggest changes of Sales are Food & Beverage (118.3 K, 16.67 %, 709.5 K to 827.8 K), Electronics (108.3 K, 36.23 %, 298.8 K to 407.1 K) and Baby (-79.3 K, -33.91 %, 233.9 K to 154.6 K).