Creating a bar in bar chart

A bar in bar chart stacks one bar chart on top of the other. Typically the two bars will have different colors and widths. Bar in bar charts can be effective in showing progress to a goal, or any two measures from the same starting point. In this recipe, we will compare the field goals made and attempted by the Phoenix Suns players in 2009 using a bar in bar chart.

Creating a bar in bar chart

Getting ready

To follow this recipe, open B05527_02 – STARTER.twbx. Use the worksheet called Bar in Bar, and connect to the Player Stats (NBA Players Regular Season 2009) data source.

Getting ready

How to do it...

The following are the steps to create a bar in bar chart:

  1. From Dimensions, drag Team Name to the Filters shelf.
  2. Under the General tab, check Suns.
  3. From Dimensions, drag Year to the Filters shelf.
  4. Under the General tab, choose 2009.
  5. From Dimensions, drag League to the Filters shelf.
  6. Under the General tab, check N for NBA.
  7. If it doesn't exist yet, create a calculated field called Player Name, and provide the following formula that concatenates First Name and Last Name:
    How to do it...

    See Appendix A, Calculated Fields Primer for more details on creating calculated fields

  8. From Dimensions, drag Player Name to the Rows shelf.
  9. From Measures, drag Field Goals Made to the Columns shelf. This creates a horizontal axis for your view.
  10. From Measures, drag Field Goals Attempted to the horizontal axis created by Field Goals Made. Do not let go of the mouse until you see the double ruler icon appear on top of the axis.
    How to do it...
  11. Change the mark from Automatic to Bar in the Marks card.
  12. Move the Measure Names pill from the Rows shelf to Color in the Marks card. Ensure that Measure Names does not exist in the Rows shelf after this step.
  13. Control drag the Measure Names pill in Color to Size in the Marks card. This creates a copy of the Measure Names pill in the Marks card, but this time to Size.
  14. Go to the Analysis top menu item, then Stack Marks and choose Off. This unstacks the marks.
    How to do it...
  15. Rearrange the measures in the Measure Values shelf so that SUM(Field Goals Made) is placed on top of SUM(Field Goals Attempted). This reverses the size and makes SUM(Field Goals Attempted) the wider bar.
    How to do it...
  16. Click on the drop-down arrow beside the color legend card and choose Edit colors….
  17. Change the colors of your bar. Assign a red color to Made, and gray to Attempted. Close the edit box when done.

How it works...

In this recipe, we started by creating a bar chart. A simple bar chart will typically have a dimension in either Rows or Columns, and a measure on the other shelf. Here we started with the Player Name dimension on Rows, and the Field Goals Made measure on Columns. When you drag another measure to the axis initially created by the measure, the original measure in the shelf gets replaced with Measure Values. This means that there are now multiple measures that are sharing the same axis.

By default when we have a shared axis chart, the bars are stacked on top of each other. The total length of the bar is cumulative total of both bars. This is great if we only care about the cumulative total. However, if you want to compare the two bars, it becomes tricky because the bars don't both start at the same starting point. The bar in bar chart can help in this case.

To create a bar in bar, we can start with the stacked bar chart, and then unstack the bars so instead of having the bars on top of each other, the bars now will start at the same point (which is zero). In Tableau, this can be done by going to the Analysis menu, and under Stack Marks, checking Off.

How it works...

When we first unstack the bar, one bar may completely mask another bar, which still makes comparing the bars difficult. A key technique here is to differentiate the bars by color and by size—this makes the bars easier to compare.

How it works...

There's more...

A bar in bar can be used to compare two measures, and can be used to track actual to goal or target. A bullet chart can also track actual to target by using a mark (bar) and a reference line. Dual axis charts can also be used for this purpose.

See also

  • Please refer to the Creating a bullet chart recipe in this chapter
  • Please refer to the Creating a combo chart (dual axis) recipe in this chapter
..................Content has been hidden....................

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