Toan Hoang

Venn Diagrams in Tableau

I was challenged a few years back to draw an interactive Venn Diagram, not just have two transparent circles, which is not too difficult, but having two circles as well as the overlap all being selectable. As you can imagine, the mathematics is going to be quite difficult, but we will go through the steps to drawing out this visualization in Tableau.

Note: As always never choose a data visualisation type and try to fit your data into it, instead, understand your data and choose the best visualization for your data consumers.

Data

Load the following data into Tableau Desktop / Public.

CategoryPath
A1
A361
B1
B361
AnB1
AnB361

Note: we need two records for each stage as we are going to be drawing polygons and using densification to get more points on our canvas.

Calculated Fields

With our data set loaded into Tableau, we are going to create the following Parameter, Calculated Fields and Bins:

P_Overlap

Note: We will use this parameter to control the amount of overlap between our two circles.

Path (Bins)

Index

INDEX()-1

Zero

0

TC_Category

WINDOW_MAX(MAX([Category]))

TC_Circle Distance from Center

WINDOW_MAX(SIN([P_Overlap]*PI()/180))

X

IF [TC_Category] = "A" THEN
    IF [P_Overlap] <= [Index] AND [Index] < (180-[P_Overlap]) THEN
        2*SIN([P_Overlap]*PI()/180)- SIN([Index]*PI()/180) - [TC_Circle Distance from Center]
    ELSE
        SIN([Index]*PI()/180) - [TC_Circle Distance from Center]
    END
ELSEIF [TC_Category] = "B" THEN
    IF [P_Overlap] <= [Index] AND [Index] < (180-[P_Overlap]) THEN
        (2*SIN([P_Overlap]*PI()/180)- SIN([Index]*PI()/180) - [TC_Circle Distance from Center]) * -1
    ELSE
        (SIN([Index]*PI()/180) - [TC_Circle Distance from Center]) * -1
    END
ELSE
    IF [P_Overlap] <= [Index] AND [Index] < (180-[P_Overlap]) THEN
        SIN([Index]*PI()/180)-SIN([P_Overlap]*PI()/180)
    ELSEIF (180+[P_Overlap]) <= [Index] AND [Index] < (360-[P_Overlap]) THEN
        SIN([Index]*PI()/180)+SIN([P_Overlap]*PI()/180)
    ELSE
        0
    END  
END

Y

IF [TC_Category] = "AnB" THEN
    IF [Index] < [P_Overlap] THEN
        COS([P_Overlap]*PI()/180)
    ELSEIF [Index] > (360-[P_Overlap]) THEN
        COS((360-[P_Overlap])*PI()/180)
    ELSEIF [Index] > (180-[P_Overlap]) AND [Index] < (180+[P_Overlap]) THEN
        COS((180-[P_Overlap])*PI()/180)
    ELSE
        COS([Index]*PI()/180)
    END
ELSE
    COS([Index]*PI()/180)  
END

Suffice to say, what we are doing with the X and Y Calculated fields looks quite crazy, however:

I would suggest going through each line to try and understand what is going on here. But using these created Calculated Fields, we are now going to build our Worksheet.

Worksheet

We are going to start building our Worksheet:

You should now see something like the following:

All that hard work creating the Calculated Fields to make sure our Worksheet is simple, well sort of, but we are not finished yet.

You should not see the following:

We have gone a long way and the only think left to do is to adjust the cosmetics of the Venn Diagram:

and with these finishing touches, you should finally have the following:

and boom, we are done with probably the most complicated article I will most likely write, but now we have a Venn Diagram that can be selectable. Granted, the mathematics involved is very tricky but I hope you can see that the options for drawing in Tableau are endless.

You can see and interact with my visualisation on Tableau Public at https://public.tableau.com/profile/toan.hoang#!/vizhome/VennDiagrams_0/VennDiagrams

Summary

I hope you all enjoyed this article as much as I enjoyed writing it, if so, please do share this article with fellow Tableau addicts and spread the love. Do let me know if you experienced any issues recreating this Visualisation, and as always, please leave a comment below or reach out to me on Twitter @Tableau_Magic.

If you like our work, do consider supporting us on Patreon, and for supporting us, we will give you early access to tutorials, exclusive videos, as well as access to current and future courses on Udemy:

Also, do be sure to check out our various courses:

Exit mobile version