Creating geographic visualizations
Tableau makes creating geographic visualizations very easy. The built-in geographic database recognizes geographic roles for fields, such as country, state, city, or zip code. Even if your data does not contain latitude and longitude values, you can simply use geographic fields to plot locations on a map. If your data contains latitude and longitude fields, you may use those instead of the generated values.
Note
Although most databases do not strictly define geographic roles for fields, Tableau will automatically assign geographic roles to the fields based on the field name and a sampling of values in the data. You can assign or re-assign geographic roles to any field by right-clicking on the field in the data pane and using the Geographic Role
option. This is also a good way of seeing what built-in geographic roles are available.
The power and flexibility of Tableau's geographic capabilities, as well as the options for customization, will be covered in more detail in the Mapping techniques section of Chapter 10,Advanced Visualizations, Techniques, Tips, and Tricks. In the following examples, we'll consider some of the foundational concepts of geographic visualizing.
Geographic visualization is incredibly valuable when you need to understand where things happen and if there are any spatial relationships within the data. Tableau offers two basic forms of geographic visualization:
- Filled maps
- Symbol maps
Filled maps
Filled maps, as the name implies, makes use of filled areas, such as country, state, county, or zip code, to show location. The color that fills the area can be used to encode values of measures or dimensions.
What if you want to understand sales for Superstore and see whether there are any patterns geographically? Let's take a look at some examples of how you can do this:
- Navigate to the
Sales by State
sheet. - Double-click on the
State
field in the data pane. Tableau automatically creates a geographic visualization using theLatitude (generated)
,Longitude (generated)
, andState
fields.
- Drag the
Sales
field from the data pane and drop it on theColor
shelf on theMarks
card. Based on the fields and shelves you've used, Tableau has switched the automatic mark type to filled maps:
The filled map fills each state with a single color to indicate the relative sum of sales for each state. The color legend, now visible in the view, gives the range of values and indicates that the state with the least sales had a total of $3,543
and the state with the most sales had a total of $1,090,616
.
When you look at the number of marks displayed on the status bar on the lower-left side, you'll see that it is 49. Careful examination reveals that the marks consist of the lower 48 states and Washington DC. Hawaii and Alaska are not shown. Tableau will only draw a geographic mark, such as a filled state if it exists in the data and is not excluded by a filter.
Observe that the map does display Canada, Mexico, and other locations not included in the data. These are part of a background image retrieved from an online map service. The state marks are then drawn on top of the background image. We'll look at how you can customize the map and even use other map services in the Mapping techniques section of Chapter 10,Advanced Visualizations, Techniques, Tips, and Tricks.
Filled maps can work well in interactive dashboards and have quite a bit of aesthetic value. However, certain kinds of analysis are very difficult with filled maps. Unlike other visualization types, where size can be used to communicate facets of the data, the size of a filled geographic region only relates to the geographical size and can make comparisons difficult. For example, which state has the highest sales? You might be tempted to say Texas or California because they appear larger, but would you have guessed Massachusetts? Some locations may be small enough that they won't even show up compared to larger areas. Use filled maps with caution and consider pairing them with other visualizations on dashboards for clear communication.
Symbol maps
Another standard type of geographic visualization available in Tableau is a symbol map. Marks on this map are not drawn as filled regions; rather, marks are shapes or symbols placed at specific geographic locations. Size, color, and shape may also be used to encode additional dimensions and measures.
Continue your analysis of Superstore sales, following these steps:
- Navigate to the
Sales by Postal Code
sheet. - Double-click on
Postal Code
underDimensions
. Tableau automatically adds postal code to theDetail
of theMarks
card andLongitude (generated)
andLatitude (generated)
toColumns
andRows
. The mark type is set to a circle by default and a single circle is drawn for each postal code at the correct latitude and longitude. You may also notice an indicator for1 unknown
postal code. We'll take a look at how to handle this in the future chapters. - Drag
Sales
fromMeasures
to theSize
shelf on theMarks
card. This causes each circle to be sized according to the sum of sales for that postal code. - Drag
Profit
fromMeasures
to theColor
shelf on theMarks
card. This encodes the mark color to correspond to the sum of profit. You can now see the geographic location of profit and sales at the same time. This is useful because you will see some locations with high sales and low profit that may require some action.
The final view should look like this after making some slight adjustments to size and color details:
Sometimes you'll want to adjust the marks on a symbol map to make them more visible. Some of the options are:
- If marks are overlapping, click on the
Color
shelf and set transparency to somewhere between 50% and 75%. Additionally, add a dark border. This makes the marks stand out and you can often discern any overlapping marks much better. - If marks are too small, click on the
Size
shelf and adjust the slider. You can also double-click on theSize
legend and edit the details of how Tableau assigns size. - If marks are too faint, double-click the
Color
legend and edit the details of how Tableau assigns a color. This is especially useful when you are using a continuous field that defines a color gradient.
A combination of tweaking the size and using SteppedÂ
Color
and UseÂ
FullÂ
ColorÂ
Range
, as shown here, produced the final result for this example:
Unlike filled maps, symbol maps allow you to use size to visually encode aspects of the data. Symbol maps also allow for greater precision. In fact, if you have latitude and longitude in your data, you can very precisely plot marks at a street address level of detail. This type of visualization allows you to map locations that do not have clearly defined boundaries. Notice that if you were to change the mark type from Automatic
to Filled Map
in the preceding view, you would get an error message indicating that filled maps are not supported at the level of detail in the view.