Pages

Tutorial: Styling Vector Data in QGIS - Basics

Please see Basic Vector Styling for an updated version of this tutorial.
To create a map, one has to style the GIS data and present it in a form that is visually informative. There are a large number of options available in QGIS to apply different types of symbology to the underlying data. In this tutorial, we will explore some basics of styling.The data we will use is from Center for Sustainability and the Global Environment (SAGE) at the University of Wisconsin-Madison. I downloaded the Life Expectancy GIS Grid data from the human impact dataset. The task is to create a map showing life expectancy in different countries of the world.

Open the shapefile in QGIS using Layer → Add Vector Layer. When prompted to choose a CRS, choose WGS84 from the list.

Right click on the layer name and click ‘Open Attribute Table’.

Explore the different attributes. To style a layer, we must pick an ‘attribute’ or a ‘column’ that would represent the map we are trying to create. Since we want to create a map showing life expectancy, i.e. the average age till a person lives in a country, the field LIFEXPCT is the attribute we want to use in styling.

Close the attribute table. Right click on the layer again and choose ‘Properties’.

The various styling options are located in the ‘Style’ tab of the Properties dialog.

Clicking on the drop-down button inthe Style dialiog, you will see there are four options available. Single Symbol, Categorized, Graduated and Rule Based. Let’s explore each of these.

Select Single Symbol. Single Symbol means all the features in the layer will be styled the same way. You can choose which color or type of outline to draw the features with. Click on Change button in the Style dialog to see these options.

Since this is a polygon dataset, you have two basic choices. You can ‘fill’ the polygon, or you can style with only ‘outline’. Among fill options, a useful feature is ‘SVG fill’ - where you can use a graphic symbol to fill your features. We will explore this in subsequent tutorials. For this exercise, you can choose ‘Simple fill’ and select a color, fill style, border color and border style. Click OK.

Click Apply in the Style dialog, and switch to the main QGIS window. you will see this style applied to your layer.

You will see that this Single Symbol style isn’t useful in communicating the life expectancy data we are trying to map. Let us explore another styling option. Choose ‘Categorized’ from the Style tab.

Categorized means the features in the layer will be shown in different shades of a color based on unique values in an attribute field. Choose ‘LIFEXPCT’ value as the Column and click ‘Classify’ at the bottom.

Click Apply and switch to the main QGIS window. You will see different countries appearing in shades of blue. Lighter shades meaning lower life expectancy and darker shades meaning higher life expectancy. This representation of the data is more useful and clearly show how life expectancy in developed countries vs. developing countries. This would be thetype of map we set out to create.

Let us explore the ‘Graduated’ symbology type in the Style dialog now. Graduated symbology type allows you to break down the data in a column in unique ‘classes’ and choose a different style for each of the classes. We can think of classifying our life expectancy data into 3 classes, ‘LOW’, ‘MEDIUM’ and ‘HIGH’. Choose ‘LIFEXPCT’ as the column and choose 3 as the classes. you will see there are many ‘Mode’ available. Let us see the logic behind each of these modes. There are 5 modes available. Equal Interval, Quantile, Natural Breaks (Jenks), Standard Deviation and Pretty Breaks. These modes use different statistical algorithms to break down the data into separate classes. Read this post from the author of these algorithms for more details.

Equal Interval - As the name suggests, this method will will create classes which are at the same size. If our data ranges from 0-100 and we want 10 classes, this method would create a class from 0-10, 10-20, 20-30 and so on - keeping each class the same size of 10 units.

Quantile - This method will decide the classes such that number of values in each class are the same. If there are 100 values and we want 4 classes, quantile method will decide the classes such that each class will have 25 values.

Natural Breaks (Jenks) - This algorithm tries to find natural groupings of data to create classes. The resulting classes will be such that there will be maximum variance between individual classes and least variance within each class.

Standard Deviation - This method will calculate the mean of the data, and create classes based on standard eviation from the mean.

Pretty Breaks - This is based on the statistical package R’s pretty algorithm. It is a bit complex, but the ‘pretty’ in the name means it creates class boundaries that are round numbers.

To keep things simple, let’s use the Quantile method. Click Classify at the bottom and you will see 3 classes show up with their corresponding values.

Click OK and switch to the main QGIS window. You will see a map showing countries in either of 3 colors representing average life expectancy in the country.

If you read the description of the Quantile method, you will expect that the number of features in each of these classes will be the same. As always, I would encourage you to verify if the algorithm gave you the results you expect. To verify this, open the Attribute Table for the layer. You will see there are 165 features in the layer. Since we chose 3 classes, we expect each class to have roughly 165/3 = 55 features. You can note the class value of the first class -99.000 - 55.6677. Now sort the attribute table by column ‘LIFEXPCT’ and go to feature number 55. You will see that there are 54 features which have the value less than 55.6677. So that matches our expectations.

Now go back to the Style dialog by right clicking the layer and choosing Properties. There are some more styling options available. You can click on the Symbol for each of the classes and choose a different style. We can choose Red, Yellow and Green fill colors to indicate low, medium and high life expectancy. Similarly click on the Range values to manually modify the upper and lower bounds. We can choose nice round values for our classes. Lastly, click on Label values to give a understandable label such as ‘LOW’, ‘MEDIUM’ and ‘HIGH’ to each class.

Click OK and see the map in the main QGIS window. This map definitely conveys a lot more useful map than the previous two attempts. There are clearly marked class names and colors to represent our interpretation of the life expectancy values.

We will explore many more options and the Rule-based styling method in a subsequent tutorial. Hope to learn about your experience with styling in QGIS in the comments.