Charting Temporal Trends in Alteryx using sugrrants R package

At times it is useful to chart Temporal Trends. This helps in understanding the cyclic and seasonal trends in Time Series Dataset.

A Temporal Trends chart for a number of downloads of a somewhat popular Android game looks as follows:

The cyclical patterns of the downloads are evident from this Temporal Trend Chart. The downloads peak around the noon time. Right about the time office workers are looking for a distraction at their jobs 🙂

While Alteryx doesn’t support Temporal Trend Charts, we can use a bit of R to accomplish this easily. The package we use to generate these charts in R is sugrrants by Earo Wang, Di Cook and Prof. Rob Hyndman

Let’s start with the data set. The input data is hourly data of number of downloads.

Date Time Number of Downloads
11/17/2016 0:00 14
11/16/2016 23:00 14
11/16/2016 22:00 15
11/16/2016 21:00 15
11/16/2016 20:00 16
11/16/2016 19:00 16
11/16/2016 18:00 15
11/16/2016 17:00 14
11/16/2016 16:00 15

This data is fed into a Alteryx Formula Tool to add the Dimensions needed for sugrrants. We will add the following dimensions to the dataset:

  1. HOUR. Integer, extracted from the Date Time in the Dataset
  2. DATE. Date type, extracted from the Date Time in the Dataset
  3. WEEKEND. Indicates if particular row is a weekend or weekday. This is useful for colour coding the trends

Next we add the R Tool to the Workflow and add the following R code in the R Tool. The R code is easy to understand and modify.

#install.packages("sugrrants", repos = "http://cran.us.r-project.org")
#install.packages("ggplot2", repos="http://cran.us.r-project.org")
#install.packages("dplyr", repos = "http://cran.us.r-project.org")



library(ggplot2)
library(sugrrants)
library(dplyr)

data_df <- read.Alteryx("#1", mode="data.frame") 
data_df$DATE <- as.Date(data_df$DATE, format = "%Y-%m-%d")



data_df <- data_df %>% frame_calendar(
 x = HOUR, y = Hourly_Counts, date = DATE, calendar = "monthly"
 )

p <- data_df %>%
 ggplot(aes(x = .HOUR, y = .Hourly_Counts, group = DATE, color = WEEKEND)) +
 geom_line() +
 theme(legend.position = "bottom")

AlteryxGraph(1, width=2400, height=1000, res=300)
prettify(p, label.padding = unit(0.08, "lines"))
invisible(dev.off())

The last step is to add Report Render tool to add the generated Temporal Chart to a Alteryx generated report.

 

Here is what the entire Alteryx Workflow looks like:

You can download a working copy of this Alteryx Workflow from Alteryx Gallery at:
https://gallery.alteryx.com/#!app/TemporalTrends/5ac12fca8a93371bd44ea6c2

Leave a Reply

Your email address will not be published. Required fields are marked *