2/13/2017
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. You can copy and paste the 3 lines into Tableau as a dataset.
Range
1
1201
Step 2: Create a BIN and 3 Calculated Fields
Range (bin) - 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
Formula:
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 Range (bin) to Columns. Right-click and select "Show Missing Values" (this turns on data densification for range-aware pills).
Move Range (bin) from Columns to Details (you can't "Show Missing Values" on Details)
Move Heart X to Columns
Move Heart Y to Rows
Set Heart X, Heart Y to Compute Using Range (bin) by right-clicking each pill, and then select "Compute Using" and 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.
Adjust the Size as desired
Other Shapes
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.
Butterfly:
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)
Flower:
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