This is an experiment to package the core functions of LUMENS as an R package. By packaging the functions, LUMENS developers could benefit from improved code organization, version control, and testing capabilities. The proposed exercise will primarily rely on the devtools.
LUMENSR
is a tool under experimental development, currently offering the Pre-QuES module. This module facilitates the analysis of land use changes by comparing land cover maps from two distinct time periods. The comparison provides valuable insights into how land use in a specific region has transformed over time.
To get started see: - Pre-QuES Report example: an example of LUMENSR report from the Pre-QuES module, process land use land cover data into meaningful information on land cover change patterns and composition. - Function reference: an overview of all LUMENSR functions
Installation:
As LUMENSR is currently under experimental development, install the latest development version from GitHub using the following commands:
install.packages("devtools")
devtools::install_github("icraf-indonesia/LUMENSR")
After installation, load the package with:
Once installed, you can use this package in the R console, within quarto documents and within Shiny applications. You may need to download the quarto CLI.
Contributing
We appreciate your feedback and contributions. Please report any problems encountered while using LUMENSR as “issues” on our GitHub repository. Your input will help us improve this package!
A minimal working example
Here’s a simple example of how to use LUMENSR:
# Load the LUMENSR package
library(LUMENSR)
# Load the example raster files for 1990 and 2020 and convert them into a terra::rast object
lc_t1 <- terra::rast(LUMENSR_example("NTT_LC90.tif"))
t1 <- 1990
lc_t2 <- terra::rast(LUMENSR_example("NTT_LC20.tif"))
t2 <- 2020
# Add a legend to the raster files using a lookup table
lc_t1_attr <- add_legend_to_categorical_raster(raster_file = lc_t1,
lookup_table = lc_lookup_klhk_sequence,
year = t1)
lc_t2_attr <- add_legend_to_categorical_raster(raster_file = lc_t2,
lookup_table = lc_lookup_klhk_sequence,
year = t2)
# Create a frequency table (crosstab) from the list of raster files
crosstab_result <- create_crosstab(c(lc_t1_attr, lc_t2_attr))
# Abbreviate the column names in the frequency table
crosstab_result_abbreviated <-
abbreviate_by_column(
df = crosstab_result$crosstab_long,
col_names = as.character(c(t1, t2)),
remove_vowels = FALSE
)
# Create a Sankey diagram from the abbreviated frequency table
# Set area_cutoff to 10000 to exclude small land cover changes
# Set change_only to FALSE to include all land cover categories
create_sankey(crosstab_result_abbreviated,
area_cutoff = 10000,
change_only = FALSE)
Interested in preparing and producing a Pre-QUES report?
Navigate to the following link for a well-commented example Quarto script. Download the qmd
files and render them using:
quarto::quarto_render("Pre-QUES.qmd")
Please explore this page to view a pre-generated Pre-QuES report.