Drawing Shapes in Tableau
Last year I presented a Think Data Thursday with Noah Salvaterra
and Chris DeMartini
called "I didn't know that was Tablossible"
. In that presentation, I did a short demonstration of how to build a heart in Tableau. Since Valentine's day is tomorrow, I thought I would post instructions on how I built the heart, and other shapes, in Tableau.
Update - Ken Flerlage was working on a very similar post around the same time as this post. Be sure to check out his approach in building a Valentine's Day viz for his wife posted here
. I especially like how he used the size of the dots for big events, for example their first date and the birth of his children. Great work Ken!
In many of my previous posts you will notice that I use a variable T for the curves that I build in Tableau, often from -6 to 6. For example, this is the starting point for building sankey diagrams in Tableau
. In that example, the values were in increments of .25, which I used to plot the points along the line. In this example I am going to do the exact same thing, but in increments of 0.01, which will create 1,201 points (also from -6 to 6).
Step 1 - Create 2 Rows of Data and Import into Tableau:
There will be one column called Range (which is the equivalent of T) and it will have two value, 1 and 1,201. This is the entire dataset.
Step 2: Create 3 Calculated Fields
- Right Click on Range and select Create and Bins. Set the size of the bins to 1 and then select OK.
Calculated Field Name: Index
Calculated Field Name: Heart X
Formula: 4 * SIN([Index])^3
Calculated Field Name: Heart Y
Formula: (3 * COS([Index]) )- 1.3 * COS(2 * [Index]) - (0.6 * COS(3 * [Index]))-(0.2 * COS(4 * [Index]))
Step 3: Build Heart
Move Heart X to Columns
Move Heart Y to Rows
Move Range (bin) to Details
Move Index to Details
Set Heart X, Heart Y and Index to Compute Using Range (bin).
Right click each pill, select Compute Using and then select Range (bin).
You should now have a heart with 1,201 marks.
Step 4: format the Heart
Select Lines from the Marks dropdown.
Select color and choose the color you want your heart to be. I used HTML: #e15759 for the heart shown below.
To create these next shapes, I imported into Tableau values for T, ranging from -6 to 6 in increments of 0.01, so this time the data set is 1,201 rows. Then I created new formulas for X and Y to create these shapes in Tableau.
Calculated Field Name: Butterfly X
Formula: sin([T]) * (EXP(cos([T]))-2 * cos(4 * [T])-sin([T]/12)^5)
Calculated Field Name: Butterfly Y
Formula: cos([T]) * (EXP(cos([T]))-2 * cos(4 * [T])-sin([T]/12)^5)
Calculated Field Name: Flower X
Formula: sin([T]) * (EXP(cos([T]))-2 * cos(8 * [T])-sin([T]/12)^5)
Calculated Field Name: Flower Y
Formula: cos([T]) * (EXP(cos([T]))-2 * cos(8 * [T])-sin([T]/12)^5)
Have a Happy Valentine's Day
I hope you find this information helpful. If you have any questions feel free to email me at Jeff@DataPlusScience.com
Jeffrey A. Shaffer
Follow on Twitter @HighVizAbility