Overview
Contingency tables are the foundation of OpenLand’s analysis framework. ThecontingencyTable() function extracts land use and cover (LUC) transitions from raster time series and organizes them into cross-tabulation matrices that serve as input for intensity analysis and visualization functions.
What Contingency Tables Contain
A contingency table (also called a cross-tabulation matrix) summarizes the transitions between land use categories from one time point to another. Each cell in the matrix represents the area (in km² or pixel count) that transitioned from category i to category j.Basic Structure
- 800 km² remained as Forest (diagonal = persistence)
- 150 km² changed from Forest to Pasture (off-diagonal = transition)
- 50 km² changed from Forest to Urban
Key Insight: Diagonal values represent persistence (no change), while off-diagonal values represent transitions (actual changes between categories).
The contingencyTable() Function
The contingencyTable() function is the entry point for OpenLand analysis. It processes raster time series and returns a structured list of data objects.
Basic Usage
Return Value
The function returns a list with 5 objects:lulc_Multistep- Transitions for all consecutive time stepslulc_Onestep- Transitions from first to last year onlytb_legend- Category names and colorstotalArea- Study area sizetotalInterval- Total time span in years
lulc_Multistep vs lulc_Onestep
OpenLand generates two types of contingency tables to support different analytical perspectives.lulc_Multistep
Captures all consecutive transitions in the time series. This table tracks how land use evolves through each time step.- Intensity Analysis (requires step-by-step transitions)
- Tracking temporal dynamics across multiple intervals
- Identifying when specific transitions occurred
- Analyzing trends over time
lulc_Onestep
Captures only the net change from the first year to the last year, ignoring intermediate states.- Sankey diagrams showing direct transitions
- Chord diagrams for overall period
- Net change analysis
- Simplified visualization of long-term change
Why Both Tables Matter
Why Both Tables Matter
Multistep captures the full trajectory of change. A pixel might transition: Forest → Pasture → Agriculture → Urban. The multistep table preserves this pathway.Onestep shows only the net result: Forest → Urban. Intermediate transitions are hidden, but you get a clearer picture of the ultimate transformation.Example:Both perspectives are valuable depending on your research question.
Table Structure and Fields
Column Descriptions
Bothlulc_Multistep and lulc_Onestep contain the same 8 columns:
| Column | Type | Description |
|---|---|---|
| Period | chr | Time interval in format “yearFrom-yearTo” (e.g., “2002-2008”) |
| From | int | Numeric code of the source category i at time t |
| To | int | Numeric code of the destination category j at time t+1 |
| km2 | dbl | Area in square kilometers that transitioned from i to j |
| QtPixel | int | Number of pixels that transitioned from i to j |
| Interval | int | Number of years between t and t+1 |
| yearFrom | int | Starting year of the transition |
| yearTo | int | Ending year of the transition |
Example Table
Important: The
From and To columns initially contain numeric category codes. After running intensityAnalysis(), these are replaced with meaningful category names from the legend table.The Legend Table (tb_legend)
The legend table maps numeric pixel values to descriptive category names and display colors.Initial State
When first created, the legend contains auto-generated values:- categoryValue: Numeric code from the raster
- categoryName: Random 3-letter code (must be edited)
- color: Random color from a predefined palette (must be edited)
Why Edit the Legend?
The auto-generated names and colors are placeholders. You must edit them to:- Provide meaningful category labels for plots and tables
- Apply appropriate colors that reflect land use types
- Control the display order in visualizations
How to Edit Legend Tables
Step 1: Define Category Names
Replace auto-generated names with meaningful labels:Important:
- Names must be in the same order as
categoryValue - Use
levelsto control the order in plots (top to bottom, left to right) - The
levelsorder determines legend and plot display order
Step 2: Assign Colors
Provide colors that visually represent each land use type:Color Specification Options
Complete Example
Understanding Factor Levels
Understanding Factor Levels
The This affects:
levels parameter in factor() controls display order in plots:- Legend order in plots
- Bar chart category sequence
- Sankey and chord diagram arrangement
Additional Table Components
totalArea
Stores the size of the study area:- area_km2: Total area in square kilometers
- QtPixel: Total number of pixels
totalInterval
Stores the total time span:yearTo (last) - yearFrom (first)
Using Contingency Tables
For Intensity Analysis
For Visualizations
Accessing and Filtering Table Data
View Specific Periods
Calculate Summary Statistics
Tip: Use
dplyr verbs like filter(), group_by(), and summarise() to explore patterns in your contingency tables before running formal analyses.Best Practices
-
Always edit the legend before creating visualizations or running intensity analysis
-
Choose colors carefully to represent land use types intuitively
- Green shades for vegetation
- Blue for water
- Gray for urban/built-up
- Brown/tan for agricultural uses
-
Order legend levels logically for better visualization
- Natural → Anthropic
- Forest → Savannah → Grassland → Agriculture
-
Verify category consistency across time steps
-
Document your legend for reproducibility
Common Tasks
Export contingency table to CSV
Export contingency table to CSV
Merge legend names into transition table
Merge legend names into transition table
Calculate net change by category
Calculate net change by category