Trends

World Population.xlsx is included in the Chapter 08 directory. It contains one record for each country for each year from 1960 to 2015, measuring population. Using this dataset, let's take a look at the historical trends of various countries. Create a view similar to the one shown in the following screenshot, which shows the change in population over time for Afghanistan and Australia. You'll notice that Country Name has been filtered to include only Afghanistan and Australia and the field has additionally been added to the Color and Label shelves:

From this visualization alone, you can make several interesting observations. The growth of the two countries' populations was fairly similar up to 1980. At that point, the population of Afghanistan went into decline until 1988 when the population of Afghanistan started to increase. At some point around 1996, the population of Afghanistan exceeded that of Australia. The gap has grown wider ever since.

While we have a sense of the two trends, they become even more obvious when we see the trend lines. Tableau offers several ways of adding trend lines:

  • From the menu, select Analysis | Trend Lines | Show Trend Lines.
  • Right-click on an empty area in the pane of the view and select Show Trend Lines.
  • Click on the Analytics tab on the left-hand sidebar to switch to the Analytics pane.
  • Drag and drop Trend Line on the trend model of your choice (we'll use Linear in this example and discuss the others later in this chapter):

Once you've added the Trend Line to your view, it should contain two trend lines, one for each country. We'll take a look at how we can customize the display shortly. For now, your view should look like this:

Trends are computed by Tableau after the query of the data source. Trend Lines are drawn based on various elements in the view:

  • The two fields that define X and Y coordinates: The fields on Rows and Columns that define the x and y axes describe coordinates, allowing Tableau to calculate various trend models. In order to show Trend Lines, you must use a continuous (green) field on both Rows and Columns. The only exception to this rule is that you may use a Discrete (blue) date field. If you use a discrete (blue) date field to define headers, the other field must be a continuous (green) field.
  • Additional fields that create multiple, distinct Trend Lines: Discrete (blue) fields on the Rows, Columns, or Color shelves can be used as factors to split a single trend line into multiple, distinct Trend Lines.
  • The trend model selected: We'll examine the differences in models in the next section.

Observe in the swap that there are two Trend Lines. Since Country Name is a discrete (blue) field on Color, it defines a trend line per color by default.

Earlier, we observed that the population of Afghanistan increased and decreased within various historical periods. Note that the Trend Lines are calculated along the entire date range. What if we want to see different Trend Lines for those time periods?

One option is to simply select the marks in the view for the time period of interest. Tableau will, by default, calculate a trend line for the current selection. Here, for example, the points for Afghanistan from 1980 to 1988 have been selected and a new trend is displayed:

Another option is to instruct Tableau to draw distinct Trend Lines using a discrete field on Rows, Columns, or Color.

Go ahead and create a calculated field called Period that defines discrete values for the different historical periods using code like this:

IF [Year] <= 1979  
  THEN "1960 to 1979"  
ELSEIF [Year] <= 1988  
  THEN "1980 to 1988" 
ELSE "1988 to 2015" 
END 

When you place it on columns, you'll get a header for each time period, which breaks the lines and causes separate trends to be shown for each time period. You'll also observe that Tableau keeps the full date range in the axis for each period. You can set an independent range by right-clicking on one of the date axes, selecting Edit Axis, and then checking the option for Independent axis range for each row or column:

In this view, transparency has been applied to Color to help the Trend Lines stand out. Additionally, the axis for Year was hidden (by unchecking the Show Header option on the field). Now you can clearly see the difference in trends for different periods of time. Australia's trends only slightly change in each period. Afghanistan's trends differed considerably.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.20.90