Tableau 7 and above have a functionality to create filled maps using fill map marks. These marks are useful when your levels of detail (or the shape of the filled area) are limited to the US counties or county/state combinations. If you want to create custom-shaded maps using geographical boundaries, such as districts of India, you have to use the following steps. You can create such filled maps using a polygon file, which consists of latitude and longitude of various points on the boundaries or shapes of the custom region. An example of such a file is shown in the following screenshot:
We'll plot the sales figures for the Upper Peninsula (UP) and Lower Peninsula (LP) of Michigan. To do so, we'll need two files: a file that contains latitude, longitude, and boundary groupings for Michigan (mipolygon.csv
) and a file that contains sales numbers for the UP and LP (misales.csv
). These files are provided with the downloadable code accompanying this book. In the following steps, we will join these two files to get all the required data and use the mipolygon
.csv file to form the boundaries and the misales
.csv file to fill the map.
After you download and save mipolygon.csv
and misales.csv
locally, perform the following steps to create a map of Michigan with the UP and LP regions filled with the sales figures:
mipolygon.csv
from your downloaded file's location and hit Open.mipolygon.csv
file is joined to the subregion option of the misales.csv
file, as shown in the following screenshot. We do so to make sure that all the records from both files where the subregions match are returned. This is called an inner join.Although we can create filled maps with Tableau 7.0 or higher, we sometimes need custom-filled maps that may not be contained in Tableau's internal data, such as regions within a state. To create such maps, we need a polygon file that has coordinates (latitude and longitude) for the area, an Order field to indicate the order of the outline of the polygon, and a grouping variable to indicate the boundaries. In this recipe, we stored two areas (north and south) and also the group field, whose coordinates fell under those two areas. You will need software such as ArcGIS to generate polygon files, which are also called shape files. Quantum GIS, an open source geographic information system, can also be used to create such a shape file. The polygon file used in this example was generated using the R language and the map_data
function of the ggplot2
package. The code to generate this file is as follows:
install.packages('maps') install.packages('ggplot2') library(maps) library(ggplot2) mimap <- map_data(map = "state", region = "michigan") write.csv(mimap, file = "mipolygon.csv", row.names = F)