Labels on custom polygons

Putting a label on a custom polygon is a little complicated as you can’t just label the polygon itself – it’s really a construct of many vertex points and you don’t want to label them. What you really want to do is label the centroid of the polygon. To do this you must create a dual-axis map. The first axis plots the polygon vertices and the second axis plots the polygon centroid. You then label the secondary axis mark.

How you define the centroid will determine how well the mark works as a labelling point. There are many ways to do this but the perhaps the simplest is to take the average lat and long values for all the vertices. However, as the following image shows this approach can be skewed if the polygons have areas of high vertex density like a coastline.


Another approach that I think yields better results in many cases is to take the midpoint of the lat and long values for all the vertices i.e. (min(x) + max(x)) /2


Again this isn’t perfect as the midpoint can be pulled away from an ideal placement if there are offshore islands (as there are in some of the above LGAs) or if the polygon is concave.

The best way is to have the optimal centroid point included in the source data e.g. pre-calculated using a more robust best-fit algorithm. Using this approach you can plot the centroid exactly where you want it. To do this you need a particular format for your data where the vertices and the centroids are in the same data source – the technique is outlined in an earlier blog post of mine.


The three techniques are compared below:


You can download a TWBX that shows these techniques from here.

About Alan Eldridge

Hi. I'm Alan. By day I manage the APAC sales engineering team for Snowflake Computing. By night, I'm a caped crusader. Or sleeping. Most often it's sleeping.
This entry was posted in Maps. Bookmark the permalink.

4 Responses to Labels on custom polygons

  1. Pingback: Using Shape Files for Boundaries in Tableau | The Last Data Bender

  2. Dan says:


    I’m confused as to how you’ve configured the workbook to only use the centroid records on the Shapes view, and only use the vertex records for the polygons.

    It may be that on the Shapes view, the Vertex records are ignored because their PointID and PolygonID are Null. But not sure how the other way round.

    Hoping you can help.


    • Hi Dan,

      There is no filtering happening (you can’t have different filters on each marks card). It’s simply some clever manipulation of the marks themselves.

      On the polygon marks the centroid value is still there. It just isn’t used when you plot a polygon because we draw the outer boundary and it is (by its very nature as a centroid) an internal feature.

      On the shape mark we are still drawing all the vertex points which is why the 1x1px transparent GIF shape is used. That way they are drawn but we just can’t see them.

      Hope that clarifies.


  3. Pingback: Hex Map Spatial File – VizPainter

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s