Comparing Plots

R-Tutorials Training
A free video tutorial from R-Tutorials Training
Data Science Education
4.4 instructor rating • 23 courses • 219,909 students

Learn more from the full course

Forecasting and Time Series Analysis in Tableau

Use Tableau to work with time series, generate forecasts and even add R functionality to enhance Tableau.

03:54:35 of on-demand video • Updated December 2018

  • visualize time series in Tableau
  • perform calculations with time series data in Tableau e.g. SMA calculations
  • use time series specific Tableau functions
  • use the Tableau forecasting tools for exponential smoothing models
  • understand the generated forecast models
  • integrate R into Tableau in order to enhance forecasting capabilities
English [Auto] Now that you know how to run different forecast models into blue it might interest you how to compare them against each other on a plot depending on the dataset. It could be useful to apply multiple models or so you can switch between workbooks with a single click. This is not the most efficient way of comparison this workbook contains three worksheets all of them use the National Park data set. The first plot shows the default table of forecast based on exponential smoothing while the to use integrated our code to run the forecasts. Each of these plots can be created based on the material presented in the previous videos here we plot the date field against the number of visitors and then we use tableaus forecasting tool to get that exponential smoothing model. The second plot features integrated our code and this script uses the forecast function with auto settings which results in this last observation carried forward model and the third plot also uses the forecast function but this time which runs on the Arema model. And these are similar are scripts like we discussed previously. So let's compare these three forecasting models on our plot. The first one is the simplest one which doesn't even require extra coding. All you have to do is to create a dashboard in place all three plots on it. You can add plot titles or captions to make it in defecation easy. So this is the first method. It features each visualization side by side. But what if you don't want to display all of them at the same time but you still want to have the option to switch between them. Well there are also practices for that at first. Let's make a visualization which allows the user to switch between the two are models. Let's create a new worksheet for that as you can see here we have two calculated fields. One contains the R script for the exponential smoothing model. The other one contains the code for the Arema math. We're going to use these two calculated fields to create a switch which consists of two parts a parameter and a further calculated field. Now keep in mind parameters make it possible to insert any values into a calculation without editing the underlying code. So let's start with this one. Create a new parameter and name it. Choose forecast model the data type is going to be integer and we are going to specify two values. This requires a list so select list the first well-you is going to be one displayed is exponential smoothing while the second value is going to be two displayed as a Riem this will make the visualization more user friendly. Let's click OK to safety parameter and let's also add it at the moment it changes nothing. Since it is not included in the calculation. So let's create a new calculated field and call it forecast models. We want to write a code which returns the exponential smoothing model if exponential smoothing is selected in the parameter and returns to uremic model. If Arema is selected for that we're going to use a simple IF statement if choose for cost model. Our parameter is equal to 1 then use the field with the exponential smoothing else returned the Arema model just close the statement with. And now we are done here so we can save the calculated field and build the visualization. That parameter is already included. So let's place the date field on the column shelf and the forecast models field on the roll shelf and that's basically it. Now you can use the parameter to set the model you want to see this worksheet can be used on its own or included in a dashboard. Now let's check out a third method where we try to compare to blossom model to our Arema model. The problem we have to face here is that tableaus model is an ad hoc calculation. While our model is contained by a calculated field recreating tableaus model in a calculated field would be a long and complex process. So we need to find a workaround. We are still going to use the parameter plus calculated field solution but this time a bit differently go to the worksheet which contains the default forecast model and create a new parameter. Let's call it select a model. This one is also going to use values from an integer list the first value is going to be 1 displayed as exponential smoothing T while the second one is to displayed as Arema are. Let's see if this parameter end added to the visualization. Now go to the worksheet which contains the Arema model and add the parameter to this one as well this which doesn't do anything just yet. So let's create a new calculated field we want to use this one as a filter. So it should return bullier data. The basic idea is that if the switch is set you Arema the Arema model should show up while exponential smoothing model should be hidden and vice versa. Since the filters and parameters connect the worksheets. This should work effortlessly. So let's call this new calculated field model filter and let's type select the model because 1. This will return true or false depending on which value is set in the select a model parameter. Now let's add this filter to the plot which uses the Arema model and X clewed the true values after that go back to the default to blow for cost model add the same filter again but this time include the true values only if we now play with the switch. The plot appears. If it is set to exponential smoothing and disappears. If Arema is set the Arema plot works the other way around. So now that the background mechanics are set and running we can bring these two plots together in a dashboard. Let's create a new dashboard and put the vertical container into it. This is extremely important. Otherwise our plots might not align perfectly. Now let's drag and drop the two plots but make sure that they go into the same container if tableau inserted. The plot titles. This is the time to hide them. You can also hide any other unnecessary cards too except the parameter control. Now the visualization is ready if we select Arema that dashboard displays the plotter with the Arema forecasting model. While if we select exponential smoothing we get the default to blue forecast model these techniques can be of course combined. For example let's say that we want a visualization which features all three plots since we want to blow to choose between an ad hoc analysis and two calculated fields. We need to stick to the parameter calculated field filter method. This time we also want to include a dummy field which will serve as a placeholder the dummy field is going to be a simple calculated field which has a serial in it. Basically it could be any numeric value but zero is probably the simplest option. Now let's create a new parameter called choose any MMOG. We're going to specify three values 1 2 and 3 and they will be displayed. The exponential smoothing our exponential smoothing and Arema no safety parameter. And create a new calculated field and this one can also be called choose any model because fields and parameters can possess the same name without a conflict. You can write the code using the if statement but for the sake of variety I'm going to use the case statement here. Case is going to be specified by that. Choose any model parameter. The integer value for your blog for cost model is one. Since this model is not contained in a calculated field this would be substituted by the dummy field. When I choose any model parameter is set to 1 then use the dummy field when the parameter is set to 2. Then use the exponential smoothing model from our else. Use the Arema Mark just close this statement with an end and save the calculated field. Now we can create a filter which is going to differentiate between true and false values. Let's name this one. Choose any model Filcher. Here we want to get true values. If the parameter is set to 1 which is the value for returning the dummy field. Therefore we are going to type choose any model parameter equals one safe to filter. And after that we can start to build our visualisation. Let's create a new worksheet and build a visualization using new date and choose any model measures. Don't worry if it doesn't give you a result yet the initial value of the parameter is 1 which means that apparently the dummy field is being returned. Let's get the parameter control and test whether the result changes if we change the value in it. It seems to be working. So let's also add the filter we created since this worksheet features the our models. Let's exclude all true values. Now we get the visualisations if we choose any of our models but we get nothing. If we choose the tableau model that's doubly Kate the worksheet which contains the Tablo model removed the filter it currently heads and add the one we created at last include the true values only. Also add the Choose any model parameter control. Now if it is set to Tobler model the plot is indeed displayed while the two other options don't give any result. So now it is time to wrap these things together and include them in a dashboard. Let's create a new dashboard and add a vertical container and one of the worksheets and the second one right below the first one. Hide the titles so the layout will blend seamlessly. Now you can choose any of the three models but using this control panel and there you have it for methods to combine plots which use calculated and ad hoc analysis. I think these techniques come really handy if you want to present visualizations for an audience even if you need to create some extra fields filters and parameters. The final result is definitely worth the work.