Learning Tableau 2020
上QQ阅读APP看书,第一时间看更新

Comparing values

Often, you will want to compare the differences between measured values across different categories. You might find yourself asking the following questions:

  • How many customers did each store serve?
  • How much energy did each wind farm produce?
  • How many patients did each doctor see?

In each case, you are looking to make a comparison (among stores, wind farms, or doctors) in terms of some quantitative measurement (number of customers, megawatts of electricity, and patients).

Let's take a look at some examples of visualizations that help answer these types of questions.

Bar charts

Here is a simple bar chart, similar to the one we built in Chapter 1, Taking Off with Tableau:

Figure 3.1: A bar chart showing the number of patient visits by department

This bar chart makes it easy to compare the number of patient visits between various departments in the hospital. As a dimension, Department slices the data according to each distinct value, such as ER, ICU, or Cardiology. It creates a header for these values because it is discrete (blue). As a measure, Number of Patient Visits gives the sum of patient visits for each department. Because it is a continuous (green) field, it defines an axis, and bars are rendered to visualize the value.

Notice that the bar chart is sorted by the department having the highest sum of patient visits at the top and the lowest at the bottom. Sorting a bar chart often adds a lot of value to the analysis because it makes it easier to make comparisons and see rank order. For example, it is easy to see that the Microbiology department has had more patient visits than the Nutrition department. If the chart wasn't sorted, this may not have been as obvious.

You can sort a view in multiple ways, as follows:

  • Click one of the sort icons on the toolbar: This results in an automatic sort of the dimension based on the measure that defined the axis. Changes in data or filtering that result in a new order will be reflected in the view:

    Figure 3.2: Toolbar sort icons

  • Click the sort icon on the axis: The option icon will become visible when you hover over the axis and will then remain in place when you enable the sort. This will also result in automatic sorting:

    Figure 3.3: Axis sort icon

  • Use the drop-down on the active dimension field and select Sort to view and edit the sorting options. You can also select Clear Sort to remove any sorting:

    Figure 3.4: Sorting using the drop-down menu

  • Use the drop-down on the field label for rows and select the desired sorting option:

    Figure 3.5: Sorting by field label

  • Drag and drop row headers to manually rearrange them. This results in a manual sort that does not get updated with data refreshes.

All of these sorting methods are specific to the view and will override any default sort you defined in the metadata.

Bar chart variations

A basic bar chart can be extended in many ways to accomplish various objectives. Consider the following variations:

  • Bullet chart to show progress towards a goal, target, or threshold
  • Bar-in-bar chart to show progress toward a target or compare two specific values within a category
  • Highlighting categories of interest
Bullet chart

A bullet graph (sometimes also called a bullet chart) is a great way to visually compare a measure with a goal, target, or threshold. The bar indicates the measure value, while the line indicates the target. Tableau also defaults to shading to indicate 60% and 80% of the distance to the goal or threshold. The line and the shading are reference lines that can be adjusted (we'll explore how in detail in future chapters):

Figure 3.6: Parts of a bullet graph

In this scenario, we'll consider how the hospital operated with respect to revenue goals. Hospital administration set the following revenue goals for 2019 and now wants to understand how each department actually performed:

Figure 3.7: Department Goals are stored in a spreadsheet as shown here

The patient visit and revenue data is contained in Hospital Visits.csv and the revenue goals are in Hospital Goals.csv. These two data connections are related together in a Data Model in both the Starter and Complete workbooks. We'll look more at the data model in Chapter 13, Understanding the Tableau Data Model, Joins, and Blends. For now, simply use the Hospital Visits & Revenue data source to complete the examples in this chapter.

We'll build a bullet graph using the Chapter 3 workbook, which contains the Hospital Visits and the Hospital Goals spreadsheet data sources. We'll use these two data sources to visualize the relationship between actual and target minutes to service as you follow these steps:

  1. Navigate to the Average Minutes to Service (Bullet Chart) sheet.
  2. Create a basic bar chart of the total Revenue per Department.
  3. Sort Department from highest to lowest.
  4. Filter Date of Admit by Year and keep only 2019 data. At this point, your view should look like this:

    Figure 3.8: Interim steps in creating the bullet graph

  5. In the Data pane, select the Goal field under the Hospital Goals.csv table.
  6. Open Show Me and select the bullet graph. At this point, Tableau will have created a bullet graph using the fields already in the view and the Goal field you selected in the data pane.

When you use Show Me to create a bullet chart, you may sometimes find that Tableau uses the fields in reverse order from what you intend (with the wrong measure defining the axis and bars, and the other defining the reference line). If this happens, simply right-click the axis and select Swap Reference Line Fields:

Figure 3.9: The Swap Reference Line Fields option

The completed bullet chart should look like the following:

Figure 3.10: The complete bullet graph

The completed bullet graph allows us to see which departments have met their goals and which are behind. Next, let's consider how we can highlight this even more.

Calling out thresholds

With bullet charts, it can be helpful to visually call out the bars that fail to meet or exceed the threshold. We'll look at calculations in depth in the next chapter, but for now, you can complete this example with the following steps:

  1. Use the drop-down arrow in the Data pane and select Create Calculated Field…:

    Figure 3.11: Creating a calculated field

  2. Name the calculated field named Goal Met? with the following code:
    SUM([Revenue]) >= SUM([Goal])
    
  3. Click OK and drag the new Goal Met? field from the data pane and drop it on Color.

The calculation returns true when the Revenue value for a department is greater than the goal value, and false otherwise. With the calculated field on Color, it becomes very easy to see which departments have met the 2019 goals:

Figure 3.12: Departments that have met their goal are highlighted in this bullet chart

Color is one of the strongest ways to get attention with your visualizations. Use color with intent. Decide whether you want to highlight good or poor performance.

Bar-in-bar chart

Another possibility for showing relationships between two values for each category is a bar-in-bar chart. Like the bullet chart, the bar-in-bar chart can show progress toward a goal. It can also be used to compare any two values. For example, you might compare revenue to a target, or you might compare the revenue for the current year to the previous year:

Figure 3.13: Bar-in-bar chart

To create this view, continue in the same workbook and follow these steps:

  1. Navigate to the Year over Year Revenue (Bar-in-Bar) sheet.
  2. Drag and drop Revenue onto the horizontal axis in the view (which gives the same results as dropping it onto the Columns shelf).
  3. Drag and drop Department Type onto Rows.
  4. Drag and drop Date of Admit onto Color. We'll discuss dates in more detail in the next section, but you'll notice that Tableau uses the year of the date to give you a stacked bar chart that looks like this:

    Figure 3.14: Interim steps in creating the bar-in-bar chart

  5. For a bar-in-bar chart, we do not want the marks to be stacked. To turn off stacking, use the main menu to select Analysis | Stack Marks | Off.
  6. All the bar segments now begin at 0 and some bars may completely obscure others. To see each bar, we'll need to adjust another visual element. In this case, hold down the Ctrl key while dragging the YEAR(Date of Admit) field that is currently on Color in the Marks card to Size.

    Holding the Ctrl key while moving a field from one shelf to another creates a copy of the field instead.

    After completing the previous step, a size legend should appear. The bars will be sized based on the year and we will be able to see all of the segments that are available, even if they overlap.

  7. We want 2019 to be in front and 2018 to be in the background, so drag and drop 2019 within the Size legend to reorder the values so that 2018 comes after 2019:

Figure 3.15: You can drag and drop items in legends to reorder them

  1. Double-click the Color legend to edit the colors so that 2019 is emphasized. A darker orange or blue for 2019 with a light gray for 2018 would serve this purpose well (though you may find other color combinations that you prefer!).

At this point, your view should look like the bar-in-bar chart that was shown in Figure 3.13 at the beginning of this section. You may wish to further enhance the visualization by doing the following:

  • Adding a border to the bars. Accomplish this by clicking the Color shelf and using the Border option.
  • Adjusting the size range to reduce the difference between the large and small extremes. Accomplish this by double-clicking the Size legend (or using the caret drop-down and selecting Edit from the menu).
  • Adjusting the sizing of the view. Accomplish this by hovering over the canvas, just over the bottom border, until the mouse cursor changes to a sizing cursor, and then click and drag to resize the view. You may also want to adjust how the view fills the space. Use the drop-down on the toolbar and experiment with the options:

    Figure 3.16: This drop-down determines how the current view is sized

  • Hiding the size legend. You may decide that the size legend does not add anything to this particular view as size was only used to allow overlapping bars to be seen. To hide any legend, use the drop-down arrow on the legend and select Hide Card:

    Figure 3.17: The Hide Card option for legends

The bar-in-bar chart gives you another way to compare values. Next, we'll consider a variation that allows us to highlight areas of interest.

Highlighting categories of interest

Let's say one of your primary responsibilities at the hospital is to monitor the number of patient visits for the ICU and Neonatal departments. You don't necessarily care about the details of other departments, but you do want to keep track of how your two departments compare with others. You might design something like this:

Figure 3.18: A bar chart with two bars highlighted via color

Now, as the data is refreshed over time, you will be able to immediately see how the two departments of interest to you compared to other departments. To create this view, follow these steps:

  1. Navigate to the ICU and Neonatal sheet.
  2. Place Department on Rows and Number of Patient Visits on Columns. Sort the bar chart in descending order.
  3. Click on the bar in the view for ICU and, while holding down the Ctrl key, click the bar for Neonatal.
  4. Hover the cursor over one of the selected bars for a few seconds and, from the menu that appears, click the Create Group button (which looks like a paperclip):

    Figure 3.19: After Ctrl + clicking the two bars, use the paperclip icon to group them

    This will create a group, which results in a new dimension, named Department (group), in the left-hand data pane. Tableau automatically assigns this field to Color.

    Ad hoc groups are powerful in Tableau. You can create groups in the view (as you did previously) or by using the menu for a dimension in the data pane and selecting Create | Group. You can use them as you would any other dimension.

  1. To add a label only to the bars for those two departments, right-click each bar and select Mark label | Always show. The label for the mark will always be shown, even if other labels are turned off for the view or the label overlaps marks or other labels.

The color will continue to make monitoring easy. The label will only show for the two departments you selected and will update with the changing data.

Now that we've considered how bar charts can be used to compare values and have walked through several examples of variations, let's turn our attention to visualizing dates and times.