dernières news, tutoriels, actualités, communautés

Tutorial : How to create a Venn Diagram in Tableau

12/04/2018

This tutorial will show you how to simply create a venn diagram in Tableau, using “sample superstore” datasource. To create this chart, you will need 5 calculated fields.

 

 

ABOUT VENN DIAGRAM

 

Also known as “Set Diagram”, a Venn Diagram is a diagram present schematic representation of all the possible logical relationships between a collection of sets. Each set is typically represented with a circle. Objects categories are presented in their circle, and cross-category objects are placed in intersections area.

 

Note : This chart is used to easily present and communicate about all category combinations, it’s used in a schematic representation. It doesn’t provide good distributions or part of total and shouldn’t be used in this way.

 

 

Prerequisite


--> Calculated Fields

--> LOD

--> Dual axis

 

 

CREATE A VENN DIAGRAM

 

1- Connect To sample superstore and get category combinations

 

 

I chose to create my example of Venn Diagram in Tableau using ‘Sample Superstore’ datasource.

 

This datasource might not be greatest to create a Venn Diagram but it will let everyone can follow this tutorial and create his own Venn Diagram.

 

To connect Tableau to sample Superstore, you just have to choose this datasource under ‘Saved Data Sources’ on Tableau first panel.

 

 

 

 

 

 

 

 

 

2 - Create a 2 sets Venn Diagram

 

In the example below, I will show you how to create a Venn Diagram presenting the number of customers who made some (at least 1) orders in 2017, those who made some orders in 2016 and the number of customers who made some orders in 2016 and in 2017.

 
  • Identify your sets and sets combinations.

 

The very first thing to do when you want to create a Venn Diagram in Tableau is to identify what are the 2 sets you want to display and create a calculated field which split your data into one of the two sets, or in between these sets.

 

To perform this, we will use LOD calculations :

In this case, we need to identify if a customer ordered in 2017, if a customer ordered in 2016 and if he/she ordered in both years 2016 and 2017. To do this, we will create the calculated field below:

 

 

> Purchased 2016 and/or 2017

{ FIXED [Customer Name]: max(if YEAR([Order Date])=2017 then 1 else 0 END)} +
{ FIXED [Customer Name]: max(if YEAR([Order Date])=2016 then 10 else 0 END)}

 


 

 

What does this calculation make ?

It uses two LOD to perform the two tests on both years. These two LOD calculation are added in ordered to have the global results of these two statements for each customer.

 

 

 

 

In this case, a customer will be linked to one of these 3 values:

1   -> The customer ordered in 2017 but not in 2016

10 -> The customer did not order in 2017 but ordered in 2016

11 -> The customer ordered in both years 2016 and 2017. First LOD (= 1) + Second LOD (=10) = 11

 

Apply and move the calculation to dimensions (must be a discrete dimension)

 

This calculation, called in this example “Purchased 2016 and/or 2017” will be used in all the next calculations we will create.
 

Now that we have a calculated field to assign one set or a combination of sets to each customer, we will create a calculated field to rename all the different categories:

 

This calculation uses the one previously created and assign for each value an understandable name.

 

 

 

> Purchased 2016 and/or 2017 Label

CASE [Purchased 2016 and/or 2017]

    WHEN 1 THEN "Year N"

    WHEN 10 THEN "Year N-1"

    WHEN 11 THEN "Year N & N-1"

END

 

 

 

 

Note: You most probably noticed that I added some comments in my calculated fields. This is my method to remember the different values assigned for each sets (1; 10). You can also write this in the sheet caption so you will always be able to find easily what is the value assigned to each set.

 

 

  • Create X and Y axis Fields

 

Now that we can identify to which category our customers belong, we can start to create the Venn Diagram.

This Venn Diagram uses simple Trigonometry formulas to position each on the sheet, using the unit circle formulas. These formulas might seem complicated but the only thing you will have to do to make your calculations work is to replace the calculated field in the CASE with the one you created at the beginning of this tutorial.

 

 

 

X axis

> axis X 2 sets

CASE [Purchased 2016 and/or 2017]

    WHEN 1 THEN COS(PI())

    WHEN 10 THEN COS(2*PI())

    WHEN 11 THEN (COS(PI()) + COS(2*PI())  )/2

END

 

 

 

 

Note : The value assigned for the customers in between the two sets is simply the average of the two previous values.

 

Y axis

The Y axis formulas will be almost the same than the X axis calculated fields, except that we will use SIN() function instead of COS().

We will also split the formula into two calculated fields in order to use dual axis features. The first calculated field will display a circle for each set, and the second one will only show a text value for the set combination category.

 

 

 

Field creating the circles

> axis Y circles 2 sets

CASE [Purchased 2016 and/or 2017]

    WHEN 1 THEN SIN(PI())

    WHEN 10 THEN SIN(2*PI())

    //WHEN 11 THEN (SIN(PI()) + SIN(2*PI())  )/2

END

 

 

 

 

Field creating the text values for sets combinations

 

> Axis Y labels 2 sets

CASE [Purchased 2016 and/or 2017]

    //WHEN 1 THEN SIN(PI())

    //WHEN 10 THEN SIN(2*PI())

    WHEN 11 THEN (SIN(PI()) + SIN(2*PI())  )/2

END

 

 

 

Then, convert the 3 axis calculated fields to continuous dimensions.

 

 

 

  • Create the chart

 

 

 

Drag axis X to columns and the two Y axis fields to rows.

 

Right-click on the second Y axis fields on rows, and select Dual axis.

 

Synchronize the axis by right clicking on the second vertical axis (right side of the sheet) and selecting synchronize axis.

 

 

 

 

 

 

 

 

 

 

 

 

 

Use the first field we created as filter to exclude value 0 ( in this example field “Purchased 2016 and/or 2017” )


Then, drag Purchased 2016 and/or 2017 Label on color shelf for both Y axis.

 

 

 

 

 

 

 

 

 

 

 

 

 

On axis Y circles 2 set, drag Purchased 2016 and/or 2017 Label as label, and the measure you want to represent on label for both Y axis (in my example, COUNTD([Customer_Name])).

Adjust labels to be in center horizontally and vertically

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Finally :

Set both marks shelfs to circles.

On field, axis Y circles 2 sets drag MAX([Number of Records]) on size and set the size to the maximum. Adjust color opacity for the circles.

 

Set axis range :
In this exemple I used a [-3,5 ; 3,5] x-axis and a [-2,5 ; 2,5] x-axis

 

 


 

 

 

 

 

 

Set opacity to 0% axis Y labels 2 sets and integrate the sheet to your Dashboard !

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3 - Create a 3 sets Venn Diagram

The method is the same as the one used for the 2 sets Venn Diagram, we just have more points and combinations. In this part I will only give you the formulas you can use, please see the 2 sets venn Diagram chapter for more explanations.

 

 

  • Define your sets and associated scores

Exemple : Customers purchasing in the 3 product categories

 

// Your_category_Set1 = 1

// Your_category_Set2 = 10

// Your_category_Set3 = 100

 

{ FIXED [Your_Row_lvl]: MAX(if [Your_category]=" Your_category_Set1" then 1 else 0 END)}+

{ FIXED [Your_Row_lvl]: MAX(if [Your_category]=" Your_category_Set2" then 10 else 0 END)}+

{ FIXED [Your_Row_lvl]: MAX(if [Your_category]=" Your_category_Set3"  then 100 else 0 END)}

 

 

 

  • Create labels for you sets

CASE [Your_Set_Definition&Scoring_Field]

    WHEN 1 THEN "Your_label_Set1"

    WHEN 10 THEN " Your_label_Set2"

    WHEN 100 THEN " Your_label_Set3"

    WHEN 11 THEN " Your_label_Set1&Set2"

    WHEN 101 THEN " Your_label_ Set1&Set3"

    WHEN 110 THEN " Your_label_Set2&Set1"

    WHEN 111 THEN " Your_label_All_Sets"

END

 

 
 
 
  • Create axis fields
> x-axis

CASE [Your_Set_Definition&Scoring_Field]

    WHEN 1 THEN COS(PI()/2+ 2*1*PI()/3)

    WHEN 10 THEN COS(PI()/2+ 2*2*PI()/3)

    WHEN 100 THEN COS(PI()/2+ 2*3*PI()/3)

    WHEN 11 THEN (COS(PI()/2+ 2*1*PI()/3) + COS(PI()/2+ 2*2*PI()/3)  ) /2

    WHEN 101 THEN (COS(PI()/2+ 2*1*PI()/3) + COS(PI()/2+ 2*3*PI()/3)  ) /2

    WHEN 110 THEN (COS(PI()/2+ 2*2*PI()/3) + COS(PI()/2+ 2*3*PI()/3)  ) /2

    WHEN 111 THEN  ( COS(PI()/2+ 2*1*PI()/3) + COS(PI()/2+ 2*2*PI()/3) + COS(PI()/2+ 2*3*PI()/3)) /3

END)

 
 
 
 
> y-axis circles sets


CASE [Your_Set_Definition&Scoring_Field]

    WHEN 1 THEN SIN(PI()/2+ 2*1*PI()/3)

    WHEN 10 THEN SIN(PI()/2+ 2*2*PI()/3)

    WHEN 100 THEN SIN(PI()/2+ 2*3*PI()/3)

END)

 
 
> y-axis labels sets


CASE [Your_Set_Definition&Scoring_Field]

 WHEN 11 THEN (SIN(PI()/2+ 2*1*PI()/3) + SIN(PI()/2+ 2*2*PI()/3)  ) /2

    WHEN 101 THEN (SIN(PI()/2+ 2*1*PI()/3) + SIN(PI()/2+ 2*3*PI()/3)  ) /2

    WHEN 110 THEN (SIN(PI()/2+ 2*2*PI()/3) + SIN(PI()/2+ 2*3*PI()/3)  ) /2

    WHEN 111 THEN  ( SIN(PI()/2+ 2*1*PI()/3) + SIN(PI()/2+ 2*2*PI()/3) + SIN(PI()/2+ 2*3*PI()/3)) /3

END)

 

  • Build Your Venn Diagram !!!

See Chapter 2 - "Create the chart"

 

 

 

Please reload

Derniers Articles
RSS Feed
Please reload

Archive
Please reload