This article describes a fairly simple method for building pixel maps. To create a pixel map, you need to convert geospatial data (continent shapes, countries) into pixels, which means dividing the map into identical polygons with assigned polygon sizes. I have an example of such a map on Tableau Public. In this example, you can switch between three types of polygons and there are two levels of data granularity (Normal and High). This map is fully interactive, allowing you to zoom in and out. By the term “pixel” on the map, we will understand a square that represents a land area on the map. In other words, we divide the entire map into squares and highlight only those pixels that represent a land area.

## 1. Examples of Pixel Maps and Methods of it Constructing

It should be noted that there are examples of pixel maps on Tableau Public, and most of these examples are built using the method of rounding latitude and longitude. You can check out Mark Bradbourne’s visualization ‘ACLED – ARMED Conflict in Africa’ and Mike Cisneros‘ visualization ‘Most Dangerous Places’. Another example can be found in my visualization ‘Rat Sightings in Manhattan’. It’s worth mentioning that all the mentioned projects were developed as part of the Makeover Monday initiative, where you can learn data visualization, see how others do it, and engage with the community.

### 1. Rounding Latitude and Longitude Method

If we briefly look at how the rounding latitude and longitude method works, its essence lies in grouping individual events on the map into squares, where the color represents the number of events. In other words, we obtain a map of event density. This can be seen in the screenshots below, where rat sighting events in Manhattan are replaced with pixel squares. Latitude and longitude values are rounded to the second decimal place in this method. It is possible to perform more complex calculations than simple rounding in order to choose any step of latitude/longitude variation.

Let’s discuss some of the challenges that arise with this visualization method:

• One of the issues with pixel maps generated by rounding latitude and longitude data is that not all areas on the maps can be filled with pixels. Only the areas for which there is data will be represented by pixels. This can result in incomplete coverage of the map, potentially leading to gaps or areas without visual representation.
• Another challenge is map zooming. If you observe my visualization ‘Rat Sightings in Manhattan’ and zoom in or out, you’ll notice that the pixel size remains the same while the map scales accordingly. Consequently, such maps are not designed to be zoomable because the pixel size calculations are valid only for a specific scale. That’s why it is common to disable the zoom functionality for these types of maps.

.

You raise another valid point regarding the nonlinearity of latitude changes in the Mercator projection. The Mercator projection is a widely used geoprojection in Tableau by default. While it has its drawbacks, it is still commonly used by many users. If you apply the method of rounding latitude and longitude, you will not achieve a uniform grid of pixels along the latitude on the Mercator projection. This becomes particularly noticeable on a world map.

Due to the nature of the Mercator projection, the distortion increases as you move away from the equator. This means that the pixel sizes, when rounded, will not accurately represent the actual geographic area. The distortion becomes more significant towards the poles, resulting in uneven pixel distribution and inaccurate representation of landmasses in higher latitudes.

It is important to be aware of these limitations and consider alternative projections or approaches if a more accurate representation of pixel grids along latitude is required, especially for global maps.

These challenges highlight the limitations of using a simple rounding method for pixel maps and the need for careful consideration when interpreting and interacting with the visualizations.

### 2. Method of Importing Data from SVG Image Files

Another approach to obtaining pixel map visualizations is exporting coordinate data from SVG files. I employed this method in the ‘USA Pixel Map‘ visualization. However, there are limitations to this method as the availability of such files is often limited, primarily created by designers. Therefore, finding a pixel map for a specific country can be challenging, and these maps are not always in the Mercator projection. Additionally, in SVG format, the data is stored as pixel coordinates on a Cartesian plane (e.g., (1,1); (12,4), etc.), rather than latitude and longitude values. As a result, without transforming the data, it is not possible to accurately overlay the SVG-based pixel map onto a geospatial layer in Tableau.

This presents challenges in terms of aligning the SVG-based pixel maps with other geospatial data in Tableau. Conversion and transformation of the pixel coordinates to latitude and longitude would be necessary to ensure correct spatial alignment.

### 3. Manual drawing method

Another approach to creating pixel maps is by drawing them manually, but this method can be time-consuming. I utilized this approach in the visualization ‘How America uses its Land’, where a significant amount of time was dedicated to manual labor.

Creating a pixel map manually involves meticulously drawing and filling in individual pixels or polygons to represent specific areas or data points. This method allows for more precise control over the map’s appearance and customization. However, it requires considerable time and effort to accurately depict the desired geographic features and ensure the correct representation of data.

While manual drawing provides a high level of flexibility and customization, it may not be practical for larger-scale or complex mapping projects due to the extensive time investment required. It is typically employed for smaller, specialized visualizations or when a high degree of control and customization is paramount.

In the method described in this article, the drawbacks mentioned above are addressed. Let’s move on to the data preparation stage.

## 2. Data Preparing

To transform a standard map into a pixel map, we need an algorithm to convert geospatial data into pixels. Such algorithms can be found in geospatial packages like QGIS, or they can be implemented in programming languages. However, in this article, I want to present the simplest way to generate such maps using the Pixel Map Generator tool. Its advantage is that you can generathttps://pixelmap.amcharts.com/e pixel maps in different map projections, choose maps of individual countries with regional breakdowns, select square, diamond, or hexagon pixels, and customize the pixel sizes.

Please note: The usage license of this tool requires mentioning and providing a link to https://pixelmap.amcharts.com. Alternatively, a commercial license can be obtained.

The generator itself is straightforward to use. You need to select the map generation options and click on ‘Generate Pixel Map.’ After that, you need to gather the data for importing into Tableau. To do this, download the data in HTML format.

I will not be using Tableau Desktop going forward and will develop everything in Tableau Public to reach a wider audience and showcase the ability to create great visualizations in Tableau Public. The Tableau Public client has a limited number of data sources available, including the JSON format.

Next, we need to extract the data from the HTML format and convert it into JSON format. In reality, the data is already present in JSON format within the HTML file, so we need to remove the unnecessary HTML code and save the data in JSON format. You can simply open the file in any text editor, delete the code fragments at the beginning and end of the file, as shown in the screenshots below. After that, save the file in JSON format.

Please note that the steps for extracting the data and saving it in JSON format may vary depending on the structure of the HTML file and the text editor you are using. The goal is to remove the surrounding HTML code and retain only the JSON data, which can then be used in Tableau Public.

You can find below two screenshots demonstrating the removal of HTML code from the beginning and from the end of the file.

That’s great! Now that you have generated the world map and saved the data in the World_Map.json file, you can proceed with importing the data into Tableau Public for visualization.

## 3. Data Connecting and Data Visualizing

When you connect to JSON data, you may notice that there are multiple schemas within the format. We are specifically interested in the dataProvider.images schema. The other data may contain color settings, formatting, and so on, which we don’t need. You can uncheck the unnecessary schemas to remove them from the visualization.

Now we can build the pixel map. The title field in the dataset represents the country name, and the images Index represents the ID of each pixel. As for the Marks, we will select squares.

Please note that when zooming in on the map, the size of the squares remains constant, which results in gaps between them.

To eliminate these gaps, we need to assign geographical coordinates to each vertex of the square. A square is a polygon with 4 vertices. Let’s add three more the same tables to the dataset in the UNION operation. When adding tables in the UNION operation, a field called Table Name will appear. Each table will represent one vertex of the square.

Now let’s create two new calculations: Lat and Long, which describe the coordinates of the vertices of each square. We will also create a numerical parameter called Scale that determines the size of the squares. Essentially, we are drawing a square on a Cartesian plane with the center at point (0,0), where Lat represents the coordinates along the Y-axis, and Long represents the coordinates along the X-axis.

Lat

[latitude]+
(
CASE RIGHT([Table Name],1)
WHEN ‘1’ THEN [Scale]
WHEN ‘2’ THEN [Scale]
WHEN ‘3’ THEN –[Scale]
WHEN ‘n’ THEN –[Scale]
END
)

Long

[longitude]+
(
CASE RIGHT([Table Name],1)
WHEN ‘1’ THEN –[Scale]
WHEN ‘2’ THEN [Scale]
WHEN ‘3’ THEN [Scale]
WHEN ‘n’ THEN –[Scale]
END
)

To perform these calculations, you need to set the Geographic Role for Lat as latitude and for Long as longitude. After that, you can create a pixel map where you select polygons as the Marks type, and place the Table Name field in the Path shelf to determine the order of vertex traversal for each polygon.

Note: When you draw something using pills with Geographic Role: Latitude and Longitude, Tableau creates multiple layers on the map (base layer, region boundaries, roads, etc.). It’s recommended to disable unnecessary layers (such as roads and region boundaries) to improve the performance of the map.

Please note that squares near the poles begin to stretch and turn into rectangles. This happens because Tableau uses the Mercator projection. To compensate for this stretching effect, you need to multiply the latitude by the cosine of the latitude angle, as the Earth is a spherical shape.

Therefore, the calculation for Lat would look like this:

Lat

[latitude]+
(
CASE RIGHT([Table Name],1)
WHEN ‘1’ THEN [Scale]
WHEN ‘2’ THEN [Scale]
WHEN ‘3’ THEN –[Scale]
WHEN ‘n’ THEN –[Scale]
END
)

After implementing these steps, the map will take on the following appearance:

Great! The pixel map is ready! You can now zoom in and out of the map, and the squares will adjust their sizes accordingly. From here, you can customize the map according to your preferences.

Feel free to explore Tableau’s features and experiment with different design elements to make the pixel map visually appealing and informative.

## 4. Custom Polygons for Pixel Maps

Above, we have discussed the option of using squares as pixels. However, it is possible to use other polygons as well, as long as the calculations are described correctly.

In my World Pixel Map visualization, you can switch to hexagons and diamonds. For these polygons, the calculations for Lat and Long will be different.

For diamonds:

Lat

[latitude]+
(
CASE RIGHT([Table Name],1)
WHEN ‘1’ THEN 0
WHEN ‘2’ THEN [Scale]
WHEN ‘3’ THEN 0
WHEN ‘n’ THEN –[Scale]
END
)

Long

[longitude]+
(
CASE RIGHT([Table Name],1)
WHEN ‘1’ THEN –[Scale]
WHEN ‘2’ THEN 0
WHEN ‘3’ THEN [Scale]
WHEN ‘n’ THEN 0
END
)

To create hexagons, you need to combine 6 tables in a UNION operation:

Lat

[latitude]+
(
CASE RIGHT([Table Name],1)
WHEN ‘1’ THEN 0
END

)

Long

[longitude]+
(
CASE RIGHT([Table Name],1)
WHEN ‘1’ THEN 0
WHEN ‘4’ THEN 0
END
)

With hexagons, the map will look like this:

Similarly, you can define calculations for other polygon shapes. Additionally, you can use different polygon shapes on the same map by tiling geometric figures.

## 5. Combining Pixel Map with Data

In the previous examples, we built pixel maps that described the geometry of countries and continents, but we didn’t overlay any real data on them. Now, we can combine the pixels on the map with actual data.

There are two common methods to combine data: using Relationships or Blending. You can also use JOIN, but keep in mind that when creating polygons (combining tables), the number of rows increases significantly.

Let’s consider four scenarios for combining data:

### 1. Data for continents, countries and regions

In this scenario, each country corresponds to one data point. Below is a screenshot of a case where the pixel map is combined with GDP data for countries in 2020, and the color is based on the GDP value. In other words, each country is shaded with a color from the Continuous color scale representing the GDP metric.

### 2. Event Density in Country/Region Territories

Essentially, we want to create a pixel map representing the density of events, where each pixel is assigned a color based on the number of events within its territory.

The most challenging task here is to calculate the number of events for each pixel. Given a list of events with their corresponding coordinates, we need to create a grid equivalent to the pixel grid, count the number of events for each pixel ID, and then merge the data.

Let’s take a look at road accidents in the United Kingdom from 2012 to 2014. The first image below shows the accidents with their actual latitude and longitude values. The second image displays the number of accidents within each pixel, obtained by rounding the latitude and longitude to the nearest decimal. The third image shows the pixel map of the United Kingdom.

We need to transfer the number of road accidents from the second image to the pixel map. If you look closely at the second image, you’ll notice that as we approach the North Pole, the distance between pixels increases. This is because in the Mercator projection, latitude changes non-linearly. Therefore, on the pixel map, the actual area of each pixel increases as latitude values increase.

Note: This is where the problem arises. If we group events on the pixel map, we will get an incorrect representation of the data due to the use of the Mercator projection.

However, it is possible to transfer the data to the pixel map. We need to match (JOIN, Relationships, Blending) the number of events to each pixel on the pixel map and color the pixels using a gradient scale. This is not the easiest task, but it can be done.

### 3. Pixel Maps with Area Data

There are cases where pixels are discretely colored based on different categories of land use. For example, a land use map of the United States shows the predominant land use categories within each pixel.

The visualization by Alex Waleczek shows a similar distribution of land in New Zealand.

### 4. Pixel Maps of Elevation or Depth

The article Dirks LEGO World Map describes the process of creating a pixel map of the world using LEGO bricks. These maps not only depict geographic information but also represent elevation or depth data. By using different colors or levels of LEGO brick assembly, it is possible to convey information about the height or depth of specific areas. This allows for the visualization of terrain relief or ocean depths on the pixel map.

Alex Waleczek wrote an interesting article about creating a height map of New Zealand. Below is the pixel map of New Zealand that he made.

Preparing data for such maps can be done using specialized geopackages, such as QGIS, or with the help of programming languages.

## Conclusion

Pixel maps are indeed an exotic form of visualization, but they are encountered in infographics and analytical articles in publications such as Bloomberg.

The advantage of such maps over traditional choropleth maps is that you can see small areas (islands) as individual pixels or clusters. For example, the country of Malta is not clearly visible on a standard map, but a pixel map can highlight it. However, a disadvantage of pixel maps is that small countries like the Vatican may get overshadowed because a larger neighboring country like Italy would occupy the pixel.

The examples mentioned above demonstrate that there are many possible applications of pixel maps, and not all of them have been fully explored.