4 Replies Latest reply on Nov 29, 2018 2:59 PM by Katrin EFFER

    Stacked bar chart: add a reference line with subtotal

    Katrin EFFER

      Hello everyone,


      I am new to Tableau and have created a stacked bar chart to show the evolution of political rights and civil liberties for selected countries.

      Each row is composed of 2 categories:

      1. PR &

      2. CL (as can be taken from the legend).


      How can I add a reference line for each row that indicates the subtotal of PR (composed of 3 subcategories) and of CL (composed of 4 subcategories)?


      And just in case: I am also struggling with changing the order of the legend, without changing the order of the subcategories in the bar chart?


      Thanks and kind regards,


        • 1. Re: Stacked bar chart: add a reference line with subtotal
          Stephen Rizzo

          Hi Katrin,


          I added the following calculated fields


          [Subtotal PR] : [Diff A Aggr] + [Diff B Aggr] + [Diff C Aggr]

          [Subtotal CL] : [Diff D Aggr] + [Diff E Aggr] + [Diff F Aggr] + [Diff G Aggr]


          Adding those under "Detail" in the "Marks" card, I was then able to add reference lines (right-click on axis, "Add Reference Line") for each row. Was that what you wanted?


          Changing the order of your legend is tricky - I would recommend putting this chart in a dashboard, then creating a separate "dummy" worksheet with the same color legend, except with the colors are in a different order. You could then display the legend from the dummy worksheet next to the stacked bar chart.


          On a side note, I would recommend rethinking how you are displaying this data. With all of these colors, stacked bars that don't always start at zero, and two reference lines that vary row-to-row, I personally found it hard to read and get useful information out of this chart. I would suggest focusing on one or two main messages that you would like to communicate with each table / chart, and tailoring the view to best focus on those. For instance, a simple horizontal bar chart showing the net change in "score" for each country, sorted in descending order (not by region) would allow your readers to easily pick out which countries had the biggest improvement and which countries had the biggest declines. Other views could then allow readers to drill into what the main contributors were to those net changes at the country level, or how those net changes roll up by region for example.

          1 of 1 people found this helpful
          • 2. Re: Stacked bar chart: add a reference line with subtotal
            Katrin EFFER

            Hello Stephen,


            thanks a lot for your detailed reply!


            Great to get feedback on the general impression - I have since adapted my viz, the workbook is attached.

            One worksheet with the top 20 countries where Freedom decreased, and another one with the top increases.

            I hope this is easier to understand?

            I dont know why there is just one figure shown with Tunisia - it might be interesting to show all of them.


            To dive into more detail of the subcategories of political rights and civil liberties, I might consider a radar chart (spider chart), if I manage to construct that


            Kind regards,


            • 3. Re: Stacked bar chart: add a reference line with subtotal
              Stephen Rizzo

              Glad to help! I like the two new views - much easier to read IMO! Two quick thoughts:


              1. What will happen in your chart if Political Rights increase but Civil Liberties decrease (or vice-versa)? Not sure the stacked bar charts will display properly in that case.
              2. I would probably recommend using a regular non-reversed axis for the top decreases chart. Might make it easier to tell that long bars indicate poor performance.


              Assuming this will be displayed in dashboard format (i.e. people can view tooltips, etc.), the image below shows how I would probably display it. Although it doesn't show in the image, hovering over the bars displays the breakdown between Civil Liberties and Political Rights.


              Top decrease freedom.png

              • 4. Re: Stacked bar chart: add a reference line with subtotal
                Katrin EFFER

                Hello Stephen,


                thanks again for your feedback and apologies for the late reply. For the stacked bar, since I am only depicting the Bottom 10 countries, I dont have the case where the bar is positive. In that case, the value on the chart actually goes to a positive number.


                I would like to keep the separation between "Civil Liberties" and "Political Rights", so for the moment I have maintained my graph, even though I am still somewhat looking to optimise my Dashboard...


                Kind regards