Online tableau training, tableau tips, & video tutorials
How to Map a Custom Background Image in TableauPreview
Plot Points on Any Image by Looking Up X / Y Coordinates
Tableau maps are technically scatter plots with data points on top of a background image. For this reason, you can plot data on top of any image! In this example, watch how to map player positions on a baseball diamond.
Hi, this is Ryan with Playfair Data TV. And in this video, I’m going to show you how to map a custom background image in Tableau. This is kind of the cornerstone of how all advanced maps are created in Tableau. Before I show you how to actually map an image, let me show you why this is the cornerstone, and I think this will help you understand how maps work in Tableau. This will help you build on this and get more advanced on future videos as well.
Over here in Tableau Desktop in the Sample Superstore dataset, I’m just going to double-click on the State dimension. And what that does in Tableau is it just generates the first type of map, which is called a symbol map. But what I wanted to point out is the location of these Longitude and Latitude pills. These are generated fields that come with every data source that includes a field that Tableau recognizes as being geographic. It’s not a coincidence that these are down here as measures, and when I created this map, it put the Latitude measure onto the Rows Shelf and the Longitude measure onto the Columns Shelf.
What’s happening because of those locations is we have a row going left to right for Latitude, so it’s creating a y-axis. And then we have a column that goes from top to bottom for the Longitude measure. So it’s creating an x-axis. You don’t see the headers there, so it’s a little bit hard to wrap your mind around this. But essentially, this is just a scatter plot. We’ve got a y-axis for Latitude, an x-axis for Longitude, and then Tableau is just drawing a data point at the intersection or a mark at the intersection of those two values.
It might be a little bit easier to envision this if I go to Map and Map Layers, and just kind of wash out the background a little bit. So it’s a scatter plot, where we’ve got a mark at the intersection, and then there’s just an image loaded behind those marks. That’s what creates all the maps in Tableau, which is why you can map a custom background image. If you know what the location is on the y-axis and the x-axis, you can look up those coordinates and draw a point. Then you can put an image of whatever you want into the background.
For this example, we’re going to map this baseball field, and I’m going to show you how to look up a few coordinates for different positions on the field. Whenever I am mapping a custom background image, I like to start with an Excel file that includes a placeholder row. The placeholder row just is going to tell Tableau what is the maximum width of this picture and the maximum height of this picture. Width is the x-axis in terms of pixels, and height is the y-axis in terms of pixels.
This is the entire data source so far, so eventually, we’re going to map all of the positions, and then I’ve got a measure for columns and a measure for rows. To get started, I just put this placeholder in there, which is going to help us lay the foundation of this to start looking up the data points.
Background images are data source-specific, so back here in Tableau Desktop, the first thing that I need to do is to connect to that data source that is containing all of my coordinates. So I’m going to go to Data, New Data Source. This is a Microsoft Excel file, so I’m going to click that first option. I had already opened it, so I’m going to choose Baseball Diamond Coordinates, and click Open. We don’t need to filter anything out. I’m just going to go to this tab to start a new worksheet to show you how this is done.
I like to name my placeholder measures, “Columns”, and “Rows”, because it makes it very intuitive on where I need to put those measures to start the view. I will put the Columns measure onto the Columns Shelf and the Rows measure onto the Rows Shelf. And at this point, we literally have a scatter plot, and that circle represents the intersection of the values on our Columns measure by the values on our Rows measure. To put an image in the background, click Map in the top navigation, and click Background Images. Again, these are data source-specific, so I need to make sure I choose the Baseball Diamond Coordinates data source.
I’m going to click on that, click Add an Image, and go find the image on my computer that I want to add into the background. I will add Baseball Diamond, and click Open. And the first thing we need to choose or determine to tell Tableau is the full range on the x-axis from left to right. Well, we want it to start at 0, and it is 800 pixels wide. So for the right side, I’m going to put in 800. Then we need to do the same thing for the y-axis. That one goes from 0 to 677. It’s very important to take note of the exact dimensions of the image, because those are the values that you’re going to want to type into these boxes.
Also, make sure that the correct field is chosen for each of the two axes. If these were reversed, I would want to click in here and make sure that x was controlling the x field, and the rows or y-axis was controlling the y field. But it looks like it picked that up automatically, so so far, so good. I’m simply telling it the x-axis will go from 0 to 800. The y-axis will go from 0 to 677.
Any time you see the Apply button in Tableau, you can click on it to preview what things are going to look like before you accept the change. Looks good so far. I saw something change, so I’ll click OK. Click OK again. And again, what we’re left with– we’ve got the same scatter plot. This one circle represents the intersection of X and Y from my Placeholder field below. But we just got an image into the background.
Now we can look up additional data points. If we wanted to map second base, for example, the way that I like to do this is to just add an annotation to look up the coordinates on the y and x-axis. You can add an annotation by right-clicking on a data point on the view, hovering over Annotate, and choose Point. By default, this annotation will include all of the fields on the view. Right now, there are only two fields on the view– Columns and Rows. So that’s exactly what I want.
I’ll go ahead and click OK, and what this annotation is telling me is the exact coordinates of second base. So second base is at 398.78. By the way, I’ve learned that the decimal places do not matter, so you can round up or down. So second base is really at 399 on the x-axis and 367 on the y-axis. I want to take note of those and go carry them over into my Excel spreadsheet, so 399 and 367. And that was second.
Back here in Tableau Desktop, let’s go ahead and find the coordinates for left field, which you can do by just dragging that endpoint for the annotation to whichever position you want to look up. Looks like left field is at 184 and 478, so 184 and 478. And that was left field. I’m just going to show you a couple of data points, because the rest of it works the exact same way. So let’s go ahead and call this good for now.
It’s very important before we go refresh that image in Tableau Desktop, we want to make sure we save this data source. That way, Tableau will be able to find the updates and then map those two new positions that we added. So I saved the data source. I’m going to go back to Tableau Desktop. Right-click on the data source, and refresh it.
What we see currently– notice that our data point moved all the way up here to the right. That has to do with the aggregation as well as the breakdown of that one circle. We need to change the level of detail. Right now, that circle represents the sum of all of the x values plus the sum of all the y values. To change the level of detail, I can put the Position dimension onto the Detail Marks Card, and we should see three data points– the Placeholder, Second Base, and Left Field.
I’m going to drop that there. It’s starting to look a little bit better. I’m going to remove this annotation by clicking on it and clicking Delete, and I’ll change the mark type to Circle, and make those circles bigger so that we can see them. Maybe I’ll also give them a brighter color.
This is looking pretty good, but watch what happens when we get rid of that Placeholder field. Which you can do in two different ways– you could delete it from the underlying file now that we kind of got things going, and we no longer need that Placeholder field. Or you can just add that Position dimension to the Filters Shelf. And I’ll just deselect Placeholder and click OK. It doesn’t quite look right anymore. It is because our y-axis and our x-axis are currently set to Automatic, so the last step when you’re mapping a custom background image is to fix those at the entire range of values for both the y-axis and the x-axis, which you can do by right-clicking on an axis and clicking Edit Axis.
And here, I will change it from an Automatic range to a Fixed range. And again, this is where I’m going to put the full range of values, so 0 to 677 was the height. You can kind of see things updating in real time below. That looks like it’s fitting the entire baseball diamond from top to bottom. But I also want to fix the x-axis at its entire range of values for the width of the image. So change that to Fixed, and this goes from 0 to 800.
And now we see the entire baseball diamond. In fact, we no longer need these axes at all. I could hide those headers, look up the rest of the data points, and now that I’ve got this, there’s some cool applications. This is just like a symbol map, so I can now encode those marks by some value. If I’m really doing an analysis on baseball, I could look at fielding percentage, for example. I’ve seen some really cool real-world applications of this. I used just a baseball diamond to help illustrate how this was done, but I hope your wheels are turning, and you’re seeing and thinking that you can literally map any image that you want.
Think of a hospital. You could have a map of a hospital, put a data point or a mark on each room, and then you could encode those marks by things like, when was the last time the patient was treated? Is the room open? Is it empty? So there’s lots of applications of this. This also serves as the cornerstone for future videos that I will be showing here, including sequential path maps as well as polygon maps.
This has been Ryan with Playfair Data TV – thanks for watching!
Related video: An Introduction to Mapping in Tableau
Related video: 3 Ways to Make Stunning Scatter Plots in Tableau
Related video: The Parallels Between Storytelling and Data Visualization
Related blog post: How to Map Any Background Image in Tableau
Related chapter: Practical Tableau – Chapter 34 – How to Map Anything in Tableau
- An Introduction to Tableau Level of Detail Expressions
- How to Use LOD Expressions to Create Benchmarks
- Exercise: Use LODs to Compare Sales to a Benchmark
- How to Normalize Current Dates and Prior Dates on One Axis in Tableau
- Using Tableau’s Parameter Actions Extension to Change Date Parts
- How to Use Parameter Actions to Change Date Parts in Tableau
- How to Dynamically Change Date Parts in Tableau
- Two Ways to Dynamically Display the Top N vs Other in Tableau
- How to Pass Filters and/or Parameters Between Tableau Workbooks
- How to Automatically Highlight Highs and Lows in Tableau
- How to Map a Custom Background Image in Tableau
- How to Compare the Last Two Full Date Parts in Tableau
- How to Compare the Last Two Partial Date Parts in Tableau
- How to Show Selections with Button Swapping in Tableau