In DataPicta, you can create bubble maps to visualize data points on a geographic map. The locations of the dots on a bubble map are typically represented by longitude and latitude coordinates, whereas the size of the bubbles represents a numerical value. A bubble map in DataPicta is basically a scatter plot overlaid on a geographic map. We will use a geographic map of the world and plot the 250 biggest cities based on their population.
The data
The data looks like this:
| City | Country | Population | Longitude | Latitude |
|---|---|---|---|---|
| Shanghai | China | 22315474 | 121.45806 | 31.22222 |
| Beijing | China | 18960744 | 116.39723 | 39.9075 |
| Shenzhen | China | 17494398 | 114.0683 | 22.54554 |
| ... | ... | ... | ... | ... |
You can download the data as a CSV file from here: 250-biggest-cities.csv.
Import the data
- Open DataPicta and start with a blank canvas.
- Click on the plus icon next to 'Data'.
- Upload the CSV file you downloaded earlier.
- Click on 'Add data' to import the data into DataPicta.
- You should now see the data in the data table.
Order the columns
A bubble map in DataPicta expects the data columns to be in a specific order: Longitude, Latitude, ...
- Click on the 'Order fields' button in the data table.
- Now use the arrow icons to move the 'Longitude' column to the first position and the 'Latitude' column to the second position.
- Click the cross icon to close the 'Order fields' dialog.
Load the geographic map
- Click on the plus icon next to 'Data'.
- Click on 'Add geo data'.
- In the dialog that appears search for 'World' and select the 'World' map.
- Click on the map preview to add it to your canvas.
Remove the country names
When you add a geographic data to DataPicta, it also automatically adds a map canvas with some default settings. We dont need the country names for this bubble map, so we will remove them.
- Click on the map canvas to open it.
- Click on the 'checkbox' for 'label' to disable the labels.
Add the Scatter Picta
- Click on the plus icon next to 'Picta'.
- Choose 'Scatter' from the list of available Pictas.
The scatter Picta will be added to your canvas, using the first two columns of your data as the X and Y coordinates. Since we ordered the columns earlier, the scatter Picta will now use the Longitude and Latitude columns for the positions of the bubbles.
Configure the bubble sizes
Next, we will configure the sizes of the bubbles to represent the population of each city. In DataPicta this can be done by adding a visual axis to the canvas.
- Click on the plus icon next to 'Canvas'.
- Choose 'Visual axis' from the list of available canvas elements.
A new panel will open, allowing you to configure the visual axis.
- We dont need a bar for the visual axis, so click twice on the 'show' chechbox to disable it.
If you would look in the data table you would see that the biggest city (Shanghai) has a population of less then 23 million people, whereas the smallest city in this list (Yancheng) has a population just above 1.5 million. We will use these two numbers to set the minimum and maximum values for the visual axis.
- Set the 'min' value to 1500000 and the 'max' value to 23000000.
Lets also set the minimum and maximum sizes for the bubbles.
- Click on 'In Range' to open the size settings.
- Set the 'min size' to 5 pixels and the 'max size' to 25 pixels.
You may also set the color of the bubbles to your liking.
- Click on 'Pick' next to 'Color' to open the color dialog.
- We choose a dark green color for the bubbles.
Disable mouse events for the map
By default, geopraphic maps in DataPicta show the region name when hovering over a region (in this case countries). Try it, hover over the map. This might be usefull in a choropleth map, but not in a bubble map where we want to show tooltips for the bubbles. So lets first disable these mouse events before adding the tooltip for the bubbles.
- Click on the map canvas to open it.
- Click the checkbox for 'Disable mouse events' to disable for the map (not for other components).
Lets also set the roaming to 'None' so that users of this chart cannot zoom or pan the map.
- Set 'Roaming' to 'None'.
Enable tooltips for the bubbles
Next, we will enable tooltips for the bubbles to show the city name and population when hovering over a bubble.
- Click the plus icon next to 'Canvas'.
- Choose 'Tooltip' from the list of available canvas elements.
The tooltip is added and opened. When you hover over a bubble now a tooltip will appear showing the population. But we want to customize the content of the tooltip to show the city name and country as well. In the tooltip formatter you can copy the following code:
'City: ' || item.data[2] || '<br />' ||
'Country: ' || item.data[3] || '<br />' ||
'Population: ' || item.data[4]
When you now hover the bubbles you will see the customized tooltip. Lets explain what we just did by breaking down the code:
In the first line we concatenate the string 'City: ' with the value in column 2 (the city name) and a HTML line break tag <br />. In the second line we do the same for the country name (column 3) and in the last line for the population (column 4), there is no need for a line break at the end.
The item variable contains information about the hovered bubble. The data property is an array containing the data values for that bubble. Since we ordered the columns earlier, the city name is in column 2, the country in column 3 and the population in column 4. Please note that the column index is zero-based, so the first column (Longitude) is index 0.
The || operator is used to concatenate strings in DataPicta.
As you can see, the tooltip is text that can contain HTML tags for formatting. If you are comfortable with HTML, you can create more advanced tooltip layouts as well. Let for instance use a table layout for the tooltip. You can copy the following code into the tooltip formatter:
'<table style="border-spacing: 8px;">' ||
'<tr><td><strong>City:</strong></td><td>' || item.data[2] || '</td></tr>' ||
'<tr><td><strong>Country:</strong></td><td>' || item.data[3] || '</td></tr>' ||
'<tr><td><strong>Population:</strong></td><td>' || item.data[4] || '</td></tr>' ||
'</table>'
Lets me be honest here, this code was created with the help of AI. There is no shame in using AI to help you with formatting HTML code.
Aspect ratio
The default aspect ratio in DataPicta is 4:3, but for a map of the world a 16:9 aspect ratio looks better.
- Click on plus icon next to 'Canvas'.
- Choose 'Aspect ratio' from the list of available canvas elements.
- In the aspect ratio settings, set the width to 16 and the height to 9.
