No Polygons
Let’s face it, polygons are scary. For those that know how to use them properly,
polygons are like Da Vinci’s paint palette or Michelangelo’s clay. But to those who don’t yet understand them
(like myself), polygons are synonymous with my two-year old nephew’s finger
paints. Polygons are scary. And because I’m still scared of polygons, I
wanted to figure out a way to create “polygon-like” visualizations without the
polygons.
One note before we begin: polygons are incredibly
powerful and if you know how to harness them, they can result in some
absolutely amazing visualizations. Some
of the most incredible visualizations that I’ve ever seen utilize polygons so I
certainly recommend that you learn them at some point in your journey. This post is not intended to make you shy
away from learning how to use them; it is simply being provided as an
alternative method that I hope others in the Tableau Community can build
upon. Now, on we go.
In my recent NFL Fan
Expectations visualization, I utilized a non-polygon method
by creating shapes in a unique way to circumvent the polygons. To be 100% transparent, there was a flaw in
my method with this viz, but I have adjusted the process slightly to remove
this flaw. I will walk through the
creation of a simpler viz (based on flowers) to demonstrate this process.
One thing to note before you proceed is that 90%
of the work involved in this process occurs outside of Tableau. It is all in the image prep. But please know that the image prep is very simple and a novice with PowerPoint and
just about any image editing software (that allows for transparency) can
complete the steps quickly and efficiently.
To start, let’s look at how custom shapes resize
within Tableau. Let’s assume you placed four shapes at x, y coordinates of 1,1,
2,1, 1,2, and 2,2. Let’s make these shapes circles as shown
below.
You can then make the shapes smaller:
Or make the shapes larger:
As you decrease or increase the size of the
shapes, you’ll see that one thing stays constant. The center of each shape remains at the exact
x, y coordinate listed in the data set.
No matter how small or how large you make a shape, the center point is
always the same.
Now that we have that knowledge in our back pocket,
let’s create some shapes. In PowerPoint,
I created the following shape, which is similar to a flower petal, but you
could use just about any shape that you like.
I copied that shape, rotated it, and changed the
color. I did this until there were four
different shapes of different color all pointed at a common center point. This is the key point to this process; all of
your shapes must share a common center point.
In the image below, I added a center point to drive this home (though
the center point will not be used in the actual viz).
In PowerPoint, select all images, group them,
then save them as a single image. Open
that image in your image editor of choice (I use Paint.net).
Next, you will need to trim off all portions of
the image except one petal. To do this,
select the portions you don’t want, then press the delete button to remove them. For this image, we will delete everything
except the yellow petal. The portion we
will delete is shown inside the dotted lines in the image below. Be careful here. You must keep the same size back ground (or
palette), so do not crop down
to the yellow petal. Simply select
everything but the yellow petal and delete it.
(As a side note, you could do all this work in PowerPoint alone by drawing
a transparent square shape, grouping it with the custom shapes, then deleting
off each shape, but I believe the method described is more straightforward).
Ensure everything but the petal is transparent
and save it as a new image (such as Yellow Petal). It should look like the following:
Do this for each petal. Once you have done so, you should have four shapes
all with the same size palette, with a transparent background, but with the
shapes in different locations on that palette.
And all shapes should share a common center point. Save these into your Shapes folder under
Tableau Repository.
Let’s bring it into Tableau. I used a fake dataset that looked at flower
sales across four regions. You can
download the sample data set using this link. (Note that for simplicity, I added Row and Column
fields that will later assist with the placement of the small multiples). You’ll notice that the X and Y coordinates in
the spreadsheet are all set at 1, 1 which is allowing us to simply stack these
custom shapes on top of each other.
- Connect to the data source and go to your
worksheet.
- Place X on Columns and Y on Rows.
- Now place Region on Detail.
- Change the chart type to Shape and drop Region onto the Shape card.
You now have a scatter plot with all the shapes stacked on top of each other because all X and Y coordinates are set to 1, 1. (If this is difficult to see, just make the shapes larger). This is difficult to look at because the shapes cover one another…it doesn’t make much sense.
Next, click on shapes and assign the four petal shapes you create earlier, one to each region. Once you apply changes, you will have four images of the exact same size stacked on top of each other. However, since the petals were located in different locations on the transparent palette, you will still see all four petals. Now, this makes more sense. (As a side note, I created the petals with a predetermined color. In reality, the petals could have been created using any single color - they could have all been black - and you could have dropped Region onto the Color card to have Tableau change the colors for you).
Increase the size of the shapes to be a bit
larger then drop Sales onto the Size card.
You will see the petals resize. Remember
earlier how the circle shapes resized around their own center point? Well the same thing just happened. The petals resized around their center point,
but we built the shapes in a way where they shared a center point and they are
perfectly resized in relationship to each other.
To see this to a greater degree, we will create
small multiples by Category. As
mentioned, I preset Columns and Rows in the data for this purpose. Go ahead and change Column and Row to
dimensions and drop Column onto the Column shelf and Row on to the Row shelf. This will create our small multiples. (You can drop Category onto the Label card
then label each small multiple using the method laid out in Ryan Sleeper’s Small
Multiples blog post - scroll about 75% of the way down the post).
There is one major issue, however. If you hover over any of the charts, you will
see that it only provides a tool tip for one region. This is because you stacked the shapes on top
of each other which means you will only see the tool tip for shape on the top
of the stack.
With this method, we will never be able to hover
over a specific petal to get specific details, but we can still provide tool
tips for each region with a simple workaround.
First, we need to create an image where the entire image is
transparent. To do this, open any image in your image editing
software; I’m using Paint.net. I
selected the following image:
Select the entire image (CTRL A), then click
delete. This should cause your entire
image to become transparent. It should
look like the following:
Save this as a shape in your Tableau
Repository. Next, create a dual axis and
synchronize the axes. On the secondary
axis, remove everything from the cards and change the chart type to Shape. Choose
your transparent image as the shape then make the shape as large as possible.
Now when you hover, you will be hovering over the
transparent shape only. In order to
provide tool tip actions, we will need to create calculated fields for each of
our regions. The calculated fields will
look like the following:
Repeat these calculations for each region (changing
the region name in the field and the calculation) then bring all of these
calculated fields onto the tooltip. Now
when you hover over each category, you will see the details for each region. In my visualization, I changed the text color
tooltip for each region to match the color of the associated petal.
And there you have it...a simple way to utilize
custom shapes as an alternative to polygons.
This trick could be used to replicate a number of
amazing visualizations that I
have seen in the past including Neil Richards’ Diversity
in Tech Companies viz and Kovacs Ivett’s Gender
& Ethnic Disparities viz. (Interestingly
enough, both Neil and Kovacs used their own alternative non-polygon techniques
for these visualizations. I’d encourage
you to download their workbooks and check out their techniques as well. This community is so creative!)
Kevin
Flerlage, October 10, 2018
No comments