Another classic spatial analysis task is calculating the areas of a certain type within regions, for example, the area within a county that is covered by certain land use types, or the share of different crops that is farmed in given municipalities.
In this recipe, we will calculate statistics of geological data for zip code areas. In particular, we will calculate the total area of each type of rock per zip code area.
To follow this recipe, load zipcodes_wake.shp and geology.shp from our sample data. Additionally, install and activate the Group Stats plugin using Plugin Manager.
Using the following steps, we can calculate the areas of certain rock types per zip code area:
The following screenshot displays the complete configuration, as well as the results:

The Group Stats plugin brings functionality, which is commonly known as pivot tables, to QGIS. A pivot table is a data summarization tool, which is commonly found in applications, such as spreadsheets or business intelligence software. As shown in this example, pivot tables can aggregate data from an input table. Additionally, the Group Stats plugin offers extended geometry functions, such as, Area and Perimeter for polygon input layers, or Length for line layers. This makes using the plugin more convenient because it is not necessary to first use Field calculator to add these geometric values to the attribute table.
It is worth noting that you always need to put the following two entries into the Value input area: