Background images allow you to plot data on top of any image. Consider the possibilities! You could plot ticket sales by seat on an image of a stadium, room occupancy on the floor plan of an office building, the number of errors by piece of equipment on a network diagram, or meteor impacts on the surface of the moon.
In this example, we'll plot the number of patients per month in various rooms in a hospital. We'll use two images of floorplans for the ground floor and second floor of the hospital. The data source is located in the Chapter 11 directory and is named Hospital.xlsx. It consists of two tabs: one for patient counts and another for room locations based on the x/y coordinates mapped to the images. We'll consider shortly how that works. You can view the completed example in the Chapter 11 Complete.twbx workbook or start from scratch using Chapter 11 Starter.twbx.
To specify a background image, use the top menu to select Map | Background Images and then click the data source to which the image applies (in this example, Hospitals). On the Background Images, screen you can add one or more images.
Here, we'll start with Hospital - Ground Floor.png, located in the Chapter 11 directory:
You'll notice that we mapped the fields X and Y (from the Locations tab) and specified the Right at 800 and Bottom at 700. This is based on the size of the image in pixels.
We'll only want to show this blueprint for the ground floor, so switching to the Options tab, we'll ensure that the condition is set based on the data. We'll also make sure to check Always Show Entire Image:
Next, repeating the preceding steps, we'll add the second image (Hospital - 2nd Floor.png) to the data source, ensuring it only shows for the 2nd Floor.
Once we have the images defined and mapped, we're ready to build a visualization. The basic idea is to build a scatterplot using the X and Y fields for axes. But we'll have to ensure that X and Y are not summed because if they are added together for multiple records, we'll no longer have a correct mapping to pixel locations. There are a couple of options:
- Use X and Y as continuous dimensions.
- Use MIN, MAX, or AVG instead of SUM, and ensure that Location is used to define the view level of detail.
- Additionally, images are measured from 0 at the top to Y at the bottom, but scatterplots start with 0 at the bottom and values increase upward. So, initially, you may see your background images appear upside-down. To get around this, we'll edit the y axis (right-click and select Edit Axis) and check the option for Reversed.
We also need to ensure that the Floor field is used in the view. This is necessary to tell Tableau which image should be displayed. At this point, we should be able to get a visualization like this:
Here, we've plotted circles with size based on the number of patients in each room. We could clean up and modify the visualization in various ways:
- Hide the x and y axes (right-click the axis and uncheck Show Header)
- Hide the header for Floor, as the image already includes the label
- Add Floor to the Filter shelf so that the end user can choose to see one floor at a time