We’ll have some fun mapping custom polygons on a baseball stadium. You’ll learn how to load a background image into Tableau, easily find coordinates, and connect the dots between points – which can be used to create any shape!
Hi. This is Ryan with Playfair Data TV. And in this video, I’m going to show you how to make a custom polygon map in Tableau.
You can actually map literally any shape in Tableau. It’s very powerful. Just to show you a few examples from my own Tableau Public Portfolio, this first view looks at the cost of attending the World Series in 2015. I admit, I created this because I’m biased. And my favorite team, the Kansas City Royals, were in the World Series that year.
But there’s two different stadiums represented in this visualization. There’s Kauffman Stadium in Kansas City and Citi Field in New York. But as you can see, these are actually encoded. Those are actual marks in a Tableau dashboard. So I can encode them by things like price is what you see here. I can hover over them, provide information via the Tooltip. And those custom polygon shapes are actually integrated in Tableau Desktop.
Here’s another example using a completely different shape. This is a custom polygon map of a football player. I was trying to show the source of concussions in the NFL. And again, these are all marks that you can hover over, or click on, or provide information via the Tooltip.
Here’s one more example of a stadium. And this will actually be what I’m going to show you how to make today. We’re going to map a few different sections in a generic stadium. And I’m going to give you a couple of kind of pro tips along the way of things that I think will help you make a custom polygon map.
You’ll have to take these techniques and apply them to whatever shape you would like. But we’re going to do a few sections in a baseball stadium. First thing you need is your image. I went ahead and purchased this royalty free image of a baseball stadium from a site called istockphoto.com before the video.
My first big tip for you that I think is going to help you later on when you go to start to make the custom map is I would put the dimensions of that image right there in the title. That’s going to help you later on when you need to tell Tableau the height and the width of this image. So this image right now is 1024 wide by 805 high. And those values are in terms of pixels. So 1,024 pixels wide from left to right, 805 pixels tall from top to bottom.
My second big tip for you is to start a dataset for all of the coordinates that you’re going to map. So I’ve created this Excel file. And notice it has just four columns in it. Point ID, that’s going to be an important Measure for us later on, which is going to tell Tableau how to connect the dots to create our nice polygon shape. Then I’ve got a column for the X-Coordinate. In parentheses I put Columns. That’s another tip for you.
The X-Coordinate draws the x-axis. So that goes on the Columns Shelf. So that’s kind of a reminder to myself on where I should put that field. So I’ve literally called it X and then Columns in parentheses. Then I have the same thing for Y. The Y-Coordinate goes on the Rows Shelf and creates a y-axis. And then Section, this is going to eventually be placed on the Detail Marks Card to break our polygon into different shapes for Tableau.
Another tip for you is I would go ahead and put in a Placeholder row. This will help you lay the foundation of the custom polygon map without having any actual values. So what I do is I just go ahead and put the first Point ID, the width of the image, the height of the image. And I call this Placeholder. This is going to allow me to go ahead and start to create the custom shapes without having any actual values in them.
So that’s the entire dataset for now. I’m ready to jump over to Tableau Desktop and connect to that Data Source. So I’ll connect to data. This is an Excel file. So I’ll click Excel and choose my Baseball Stadium. Click Open. That will connect to my Data Source. There’s my four columns, one single row. I’m ready to start using that Data Source. So I’ll go to a Tab.
The reason that I recommend you put in that Placeholder row and name the X Measure Columns and the Y Measure Rows is because I can go ahead and start to lay the foundation for this without having any actual data. I’m going to put the X-Coordinate on the Columns Shelf and the Y-Coordinate on the Rows Shelf. That should generate a y-axis for me that is the same height as my image, 805, and an x-axis for me that is the same width as my image, which is 1,024.
And sure enough, it looks like that is what’s happening. I can get extra confirmation by hovering over that and seeing the exact values. All right, let me make sure I had that– for some reason, I was one number off. Instead of 806, it’s actually 805. So that was bugging me. Let me go ahead and fix that. Click Save and refresh this.
I don’t mind you seeing this. Because this is part of the process. And that actually shows you how easy it is just to move all these points one pixel. What you might have to do to get the exact result that you’d like. Now that I saved and refreshed the Data Source, now it’s 805 instead of 806. So it’s the exact dimensions as my image.
To map that image, you click map in the top navigation and hover over background images. Each background image is tied to a specific Data Source. So if you’re connecting to more than one Data Source, you could see more than one option here. We’re only connecting to one thing. So I’m going to click that one Data Source, which will open a dialogue, where I can add an image. I will click Add Image, go find that image on my computer, click Open. That loads the image.
But we don’t see anything change yet in the background. We just see the image in this dialogue. There’s a couple of little setup steps we need to do. First, we need to set the range of the X Field. This will go from 0 on the left to as wide as my image is on the right. That’s why I recommend you put the dimensions right here in the title. Because I don’t have to go back and look at my Data Source. I can see that 1,024 is going to be the maximum range from left to right.
So in this box, I’ll type 1,024. For the Y Field it will go from 0 to 805. The one pitfall in this section is if Tableau gets these backwards. So if this said Y and this said X, my image would be flipped. So just make sure your X Field is associated with your X Field and your Y Field is associated with the Y Field. Makes sense, right?
Now, I’ll click Apply, just to see if anything shows up in the background. Well, it looks pretty good. I’ll click OK. Click OK again. And right now we have a single coordinate. And that single coordinate represents the total x values added together by the total y values added together. And because there is only a single row, it just comes out at 1,024 by 805. We’ve also got the image in the background.
But now we need to look up the data points to draw these shapes on the view. For the purposes of this video, I’m going to go ahead and map the entire upper level. To map a data point and look up its coordinates, the easiest way to do that is to Right-Click on the data point, hover over Annotate, and click Point. By default, that annotation is going to show you all of the fields on the view. There’s only two fields on the view right now, Columns and Rows.
So that’s what shows up here. Notice the gray shading. The gray shading tells me which values will be dynamic. Meaning that if I move this annotation around, it will dynamically update to show me the x value and the y value for wherever I moved it to. So that’s actually exactly what I want. So I’ll go ahead and click OK. I am going to make some small tweaks to this annotation, just to make it a little bit easier to read.
I’m going to Right-Click in it and click Format. And I’m going to make the Line End a Circle, or a Dot, is what Tableau calls it. Let me make that dot a little bit bigger. And the reason I’m doing that is I now have something a little bit more of substance to grab onto and move around. So I can click on that dot, drag it anywhere I’d like. And you can see the coordinates updating in that annotation.
So I’m going to put that as close as I can to this first point that I want to map, right there on the corner. The other thing that I want to change is I want to get rid of the decimals on this annotation. These xy coordinates round anyway. So the decimals aren’t going to do anything for us. So I’m going to get rid of those by changing the format of each of my Measures on the Columns and Rows Shelf.
So I’ll click Rows. Make sure you’re on the Pane Tab. It’s this numbers dropdown. I’ll go Number, Custom, bump the decimals down to zero. I did that for both the X-Coordinate and the Y-Coordinate. And this is actually the first data point that I want to put in my dataset.
So I’ll go back over here to the dataset. This is the second point that I’m plotting. And this is 106 by 321, so 106 by 321. The Section this time is Upper Left Field. I’m now going to move that annotation down to the second point. And this is going to be 244 by 283, so 244 by 283. That’s my third point ID. This is also Upper Left Field. And I’m going to do four and five for Upper Left Field.
So I’ll go ahead and prepopulate those, move this cursor to the third point, 247 and 440, 247, 440. And then I’m going to move it to the fourth point in the Upper Left Section, which is 105 and 479, 105 and 479. OK, one little thing that you can use to be extremely precise is you can look at some of these x and y-coordinates to see if they line up.
Let me show you what I mean by that. That last data, 105 and 479, well, theoretically, that data point if I’m just eyeballing this on the view right now, it’s exactly vertical from point number one in the upper left field. So I could go look at that and see well, that was at 106. So just by eyeballing it, I was a little bit off. So maybe I’ll bump that to 106, just to get that to line up very precisely. And these are all Upper Left Field. And let’s go see how we did. I’m going to click Save. I purposely did one thing wrong here to show you how this works.
But I’m going to refresh my Data Source. So we’ve added four data points. And I’ve refreshed the Data Source. So that it shows up over here in Tableau. Remember, that one circle right now is still the SUM of all of the x values and all of the y values. We haven’t broken it down by any section yet. So that’s why we’re seeing this kind of shape way up here in the top right corner.
The first thing I’m going to do is change the Mark Type from Automatic, which is Shape– and it’s drawing one open circle to polygon. And you see that go away temporarily. But now, I need to tell Tableau how to connect the dots to create these shapes for us. And that’s where that Point ID field comes in. Very critical step is that Point ID field needs to be added to the Path Marks Card. That’s what tells Tableau what order to connect these dots in.
OK, we see a polygon show up. But we’ve got kind of this weird geometrical shape right now. The reason for that is if you look at our dataset again, we had one point for the Placeholder, then these all went in sequential order. So what it’s doing right now by default is it’s starting up here at number one then going to two, three, four, five, which is why we get that odd shape.
There’s a few ways that we could fix this. We could get rid of the Placeholder Field. We could drag the Section Dimension to the Detail Marks Card. And that’s already solved it. We could also restart the point orders for each section. So those decisions are going to kind of be up to you. It will be a little bit more complex once we go to add the second and third sections.
So what I would likely do is go ahead and put– so first, the most critical thing, Point ID on the Path Marks Card, I’d go ahead and put whatever level of granularity you want to break the polygons down by onto the Detail Marks Card. In my example, I’m looking at three different sections. So Section is the granularity. That’s what goes onto the Detail Marks Card.
And then just to be safe, I’d probably also go ahead and restart the Point IDs at each Section level. So for Upper Left Field, I restarted it at one, two, three, four. I’ll save that. Refresh the Data Source. And we shouldn’t see anything change. And we don’t.
So so far, so good. We’ve got one nice polygon on the view. I’m now going to add the Center Field section. It has four data points. I’ll go ahead and type Center Field and make rows for four options. I’ll copy the Point IDs again. So we’ve got one, two, three, four. And I’ll go up and look those points up now.
One shortcut for you, not only a shortcut, but also, it’s going to help you make these polygons as precise and crisp as possible. Remember, so this is point number one for Center Field. But it’s also point number four for Left field. So it’s the exact same value. So don’t move anything and you’ll have a nice connecting point between left field in center field. So point number one is 105 by 479, 105 by 479. And of course, I forgot. That was actually 106. Remember, we bumped that up already, so 106 by 479.
Point two, if I wanted to make another shortcut, is also point number three from the Upper Left Field. So I could also go copy point number three from Upper Left Field. And that becomes point number two for Center Field. The last two I’ll have to look up though. So I’ll move that cursor with my annotation over to spot number three. That’s 405 by 532, so 405 by 532. And then we’ve got fourth point is 366 by 628, 366 by 628.
Let’s also, before we refresh, go ahead and do Upper Right Field. It’s got four data points. I’ll copy Point IDs one through four. And again, two of these points we can copy from what we already had. So I look at Tableau. Point number one is going to be the same as point number four for Center Field.
So I could just copy the same data points I just put in there. And then if I go this direction, point number two would be the same thing as point number three for Center Field. So I’ll copy point number three. But points number three and four I’ll have to look up again. So I’ll move the cursor to point number three, 711, and 532. And then point number four should be directly above point number three.
So for the X-Coordinate, I could make sure it’s the exact same thing, 711. But the Y-Coordinate is going to be 631, 631. I’ve mapped all three of the sections in the upper level. I’ll click Save, go refresh this to see how it looks. Those new data points come in. You can see because we shared the coordinates between the third and fourth points between each section and the first and second points, they line up perfectly. This has been very precise.
So that we can see the sections a little bit better, I’m going to click on the Color Marks Card and add a white border, just so we can see them. And I’m going to call this good for the purposes of time. So I’m going to get rid of my annotation and assume that I’m done mapping for the moment.
But we’ve just created a Custom Polygon Map of the upper deck in this baseball stadium. It was a little bit of manual effort. But it’s only taken a few minutes. And we’ve pretty much done half the stadium already. And the great thing about this technique is you only have to do it one time. And then you can repurpose these coordinates over and over for various analysis.
Also, now that I’ve mapped it one time, I could either JOIN this Data Source to something else that has some of my actual measures in it . Or I could add Measures to this Data Source itself. So for example. So now that I’ve got the polygons on the view, I can encode them by different Measures.
So for example, attendance– and maybe I’ll get rid of this Placeholder row at this point. That’s not even showing up on the view anymore. But let’s pretend that I’ve got some attendance data. I’ll start with Center Field, which is probably the most popular section in the Upper Deck. And we’ll say that it gets 85% attendance. And I’ll put that in there for all four points on Center Field. I’ll deduplicate that later with my aggregation. I’ll choose either MIN, MAX, or AVG to fix that.
For Upper Left Field, we’ll say that this is the second most popular section. Because people want to hang out in Left Field, see if they can catch a Home Run Ball. So we’ll say that that gets 0.65 attendance. And then the Upper Right Deck is our least popular section. We’ll say that that comes in at 40% attendance, so 0.4. And I’ll populate that, click Save, go refresh my Data Source again.
We should see a new Measure pop into the view. Oh, here’s an interesting little wrinkle. Notice when I refresh this, it changed the coordinate. So one last thing I need to show you on the custom polygon map, we always want the entire baseball stadium to show up. So we want to modify, or fix, the axis at the full axis range. So y went from 0 to 805.
So I will right-click on the axis, click Edit Axis, and make it Fixed. What was happening is Tableau is trying to help us by zooming into the most relevant area of the image. But in this case, we always want the entire image to show up. So if I type in 805, we now should see the entire stadium from top to bottom. And I need to do the same thing on the x-axis and make that go from zero to 1,024.
And then we should see the entire width of the image appear, and we do. And in fact, at this point, we no longer need those axis. So you can hide those, et cetera. But the last thing I wanted to show you is how to encode those polygons.
So after refreshing the Data Source, I see a new Measure. It’s called Attendance. I can drag that to the Color Marks Card. It’s summing up the attendance, which is duplicating the row. So I’ll change that to AVG. So the color looks at average attendance. And now you can see, the higher the attendance, the darker the blue, the lower the attendance, the lighter the blue.
Maybe I will edit the colors and make this a diverging palette. Click Apply. Kind of play around with the step levels if I’d like to. So at this point, Center Field is my best performer. It’s in blue. My Left Field is kind of average and OK. It’s kind of a grayish color. And Right Field is doing worse and it’s encoded red.
So I just showed you how to make a custom polygon map in Tableau out of any shape or image that you would like. But I also wanted to show you that that’s not just a cool design feature. You can use it to then encode those polygons and come up with some really practical analysis.
This has been Ryan with Playfair Data TV. Thanks for watching!