In this post, we shall learn how to map the 2023 StatiSense murder cases data in Nigeria by geopolitical zone.
To map the geopolitical zones dataset, we can use several essential mapping tools to build a choropleth map including using QGIS or Python with geopandas and matplotlib.
To map this dataset in QGIS, we need to link the regional numbers to a digital map layer (Shapefile or GeoJSON) of Nigeria. Here is the exact step-by-step process to build the choropleth map.
Step 1: Download Nigeria's Geographic Data
QGIS needs a base map of Nigeria divided by states or geopolitical zones.
- Go to a public repository like GRID3 Nigeria or Humdata.
- Search for and download the Nigeria Administrative Boundary Level 1 (States) Shapefile.
- Extract the downloaded
.zipfile into a dedicated folder on your computer.
Step 2: Prepare Your Murder Dataset
Create a clean spreadsheet so QGIS can read your numbers correctly.
- Open Excel or Google Sheets.
- Create two columns named exactly:
ZoneandMurders. - Fill in the data carefully:
- North Central | 436
- North West | 417
- North East | 345
- South West | 174
- South East | 169
- Save the file as a CSV (Comma Delimited) file named
nigeria_murders.csv.
Step 3: Load Data into QGIS
- Open QGIS Desktop.
- Click Layer -> Add Layer -> Add Vector Layer.
- Browse to your extracted shapefile folder, select the file ending in
.shp, and click Add. - Click Layer -> Add Layer -> Add Delimited Text Layer.
- Select your
nigeria_murders.csvfile. - Under Geometry Definition, choose No geometry (attribute table only), then click Add.
Step 4: Group States into Geopolitical Zones
Note: If your downloaded shapefile already has a "Zone" column, you can skip to Step 5.
- Right-click your Nigeria shapefile layer in the Layers panel and select Open Attribute Table.
- Click the Toggle Editing Mode icon (the yellow pencil).
- Click Open Field Calculator.
- Set the Output field name to
Zoneand change the field type to Text (string). - In the expression box, use a
CASEstatement to group the states. For example:sqlCASE WHEN "name" IN ('Kano', 'Kaduna', 'Katsina', 'Kebbi', 'Sokoto', 'Zamfara', 'Jigawa') THEN 'North West' WHEN "name" IN ('Kwara', 'Niger', 'Kogi', 'Benue', 'Plateau', 'Nasirawa', 'FCT') THEN 'North Central' -- Repeat for other zones based on the states in your shapefile ENDCASE WHEN "name" IN ('Kano', 'Kaduna', 'Katsina', 'Kebbi', 'Sokoto', 'Zamfara', 'Jigawa') THEN 'North West' WHEN "name" IN ('Kwara', 'Niger', 'Kogi', 'Benue', 'Plateau', 'Nasirawa', 'FCT') THEN 'North Central' -- Repeat for other zones based on the states in your shapefile END - Click OK, save edits, and turn off the pencil icon.
Step 5: Join the Dataset to the Map
- Right-click your Nigeria shapefile layer and select Properties.
- Click on the Joins tab on the left sidebar.
- Click the Green Plus (+) button at the bottom.
- Set Join layer to
nigeria_murders. - Set Join field to
Zone. - Set Target field to the
Zonecolumn you verified in Step 4. - Click OK, then click Apply.
Step 6: Style the Choropleth Map
- While still in the Layer Properties window, click the Symbology tab on the left.
- Change the top dropdown from Single Symbol to Graduated.
- Set the Value dropdown field to your joined murder column (e.g.,
nigeria_murders_Murders). - Choose a color gradient under Color ramp (e.g., Oranges or Reds).
- Change the Mode dropdown at the bottom to Pretty Breaks or Natural Breaks (Jenks).
- Click the Classify button to generate the color brackets.
- Click OK. Your map will now display the data visually across Nigeria.
Step 7: Export Your Map Image
- Click Project -> New Print Layout, give it a name, and press OK.
- Click Add Item -> Add Map, then click and drag your mouse across the white canvas canvas to draw the map.
- Click Add Item -> Add Legend and click on an empty space to drop a color key.
- Go to Layout -> Export as Image to save your map as a clean PNG or JPEG file.
Python with geopandas and matplotlib
import geopandas as gpd import matplotlib.pyplot as plt %matplotlib inline # 1. Initialize dataset with the StatiSense data data = { 'Zone': ['North Central', 'North West', 'North East', 'South West', 'South East'], 'Murders': [436, 417, 345, 174, 169] } # 2. Load Nigeria's geographic boundary shapefile # (Ensure you have a valid GeoJSON or Shapefile path with a 'zone' column) nigeria_map = gpd.read_file(r"C:\Users\08039508010\SHP\NIG.gpkg") # 3. Merge tabular data with spatial data merged_map = nigeria_map.set_index('zone').join(gpd.GeoDataFrame(data).set_index('Zone')) # 4. Plot the choropleth map fig, ax = plt.subplots(1, 1, figsize=(10, 8)) merged_map.plot( column='Murders', cmap='Blues', linewidth=0.8, ax=ax, edgecolor='0.8', legend=True, missing_kwds={"color": "lightgrey", "label": "Data Unavailable"} # For South South ) # 5. Save the map directly to your folder fig.savefig('nigeria_murder_map.png', dpi=300, bbox_inches='tight') print("Map successfully saved as 'nigeria_murder_map.png'") # 6. Customize layout boundaries ax.axis('off') ax.set_title('2023 Reported Murder Cases in Nigeria by Zone', fontdict={'fontsize': '16', 'fontweight': '3'}) plt.show()
Thank you for reading.


No comments:
Post a Comment