Skip to main content

Overview

The netgrossplot() function creates a stacked bar plot showing net and gross changes of land use and cover (LUC) categories during the entire analyzed time period. This visualization helps distinguish between total change (gross) and directional change (net gain or loss).

Function Signature

netgrossplot(
  dataset,
  legendtable,
  title = NULL,
  xlab = "LUC category",
  ylab = "Area (Km2)",
  legend_title = "Changes",
  changesLabel = c(GC = "Gross change", NG = "Net gain", NL = "Net loss"),
  color = c(GC = "gray70", NG = "#006400", NL = "#EE2C2C"),
  area_km2 = TRUE
)

Parameters

dataset
data.frame
required
A table of multi-step transitions (lulc_Multistep) generated by contingencyTable().
legendtable
data.frame
required
A table containing the LUC legend items and their respective colors (tb_legend).
title
character
default:"NULL"
The title of the plot. Use NULL for no title.
xlab
character
default:"LUC category"
Label for the x-axis.
ylab
character
default:"Area (Km2)"
Label for the y-axis.
legend_title
character
default:"Changes"
The title displayed in the legend.
changesLabel
named character vector
Labels for the three types of changes. Must be a named vector with names GC, NG, and NL.
color
named character vector
A named vector defining the three bar colors for gross change, net gain, and net loss.
area_km2
logical
default:"TRUE"
If TRUE, changes are computed in km²; if FALSE, in pixel counts.

Return Value

Returns a ggplot2 bar plot object showing:
  • Wide gray bars representing gross change (total transitions in or out)
  • Narrow colored bars representing net change (net gain or net loss)
  • Horizontal line at zero separating gains from losses
  • Bars grouped by land use category

Usage Examples

Basic Net/Gross Plot

library(OpenLand)

# Prepare the legend
SL_2002_2014$tb_legend$categoryName <- factor(
  c("Ap", "FF", "SA", "SG", "aa", "SF", "Agua", "Iu", "Ac", "R", "Im"),
  levels = c("FF", "SF", "SA", "SG", "aa", "Ap", "Ac", "Im", "Iu", "Agua", "R")
)

# Create net/gross plot
netgrossplot(
  dataset = SL_2002_2014$lulc_Multistep,
  legendtable = SL_2002_2014$tb_legend,
  xlab = "LUC Category",
  ylab = bquote("Area (" ~ km^2 ~ ")")
)

Custom Colors and Labels

netgrossplot(
  dataset = SL_2002_2014$lulc_Multistep,
  legendtable = SL_2002_2014$tb_legend,
  xlab = "LUC Category",
  ylab = bquote("Area (" ~ km^2 ~ ")"),
  changesLabel = c(
    GC = "Gross changes",
    NG = "Net Gain",
    NL = "Net Loss"
  ),
  color = c(
    GC = "gray70",
    NG = "#006400",   # Dark green for gains
    NL = "#EE2C2C"    # Red for losses
  )
)

With Title and Custom Legend

netgrossplot(
  dataset = SL_2002_2014$lulc_Multistep,
  legendtable = SL_2002_2014$tb_legend,
  title = "Net and Gross Changes (2002-2014)",
  xlab = "Land Use Category",
  ylab = "Area (km²)",
  legend_title = "Change Type",
  changesLabel = c(
    GC = "Total Change",
    NG = "Gained Area",
    NL = "Lost Area"
  ),
  color = c(
    GC = "#CCCCCC",
    NG = "#2E7D32",
    NL = "#C62828"
  )
)

Interpretation Guide

Understanding the Plot

  • Wide bars (Gross change): Total amount of change, regardless of direction
    • Calculated as the sum of all gains + all losses for a category
    • Always positive
    • Indicates the overall dynamics of a category
  • Narrow bars (Net change): Directional change
    • Above zero (Net gain): Category increased in area
    • Below zero (Net loss): Category decreased in area
    • Calculated as total gains minus total losses
  • Horizontal line at zero: Reference line separating gains from losses

Example Interpretation

# If a category shows:
# - Large gross change bar (e.g., 500 km²)
# - Small net gain bar (e.g., +50 km²)
# 
# This means:
# - The category experienced substantial turnover (500 km² total)
# - But only slight overall increase (+50 km²)
# - Indicating many pixels converted TO and FROM this category
Categories with high gross change but low net change are experiencing significant spatial reorganization without major area change.

Saving the Plot

As a ggplot2 object, save using ggsave():
# Create the plot
p <- netgrossplot(
  dataset = SL_2002_2014$lulc_Multistep,
  legendtable = SL_2002_2014$tb_legend
)

# Save as PNG
ggsave(
  "netgross_plot.png",
  plot = p,
  width = 10,
  height = 6,
  dpi = 300
)

# Save as PDF
ggsave(
  "netgross_plot.pdf",
  plot = p,
  width = 10,
  height = 6
)

Advanced Customization

Using Pixel Counts

netgrossplot(
  dataset = SL_2002_2014$lulc_Multistep,
  legendtable = SL_2002_2014$tb_legend,
  area_km2 = FALSE,
  ylab = "Number of Pixels"
)

Adding ggplot2 Theme Elements

Since this returns a ggplot2 object, you can add additional customization:
library(ggplot2)

netgrossplot(
  dataset = SL_2002_2014$lulc_Multistep,
  legendtable = SL_2002_2014$tb_legend
) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    legend.position = "bottom"
  )
Compare net and gross changes to identify categories with high turnover but stable total area.

See Also

Build docs developers (and LLMs) love