knitr::opts_chunk$set( collapse = TRUE, fig.width=8.5, fig.height=6, comment = "#>" )
Is an R package for analyzing the trajectories of a category during a time series. The trajectories can be a combination of the following: 1. Mask 2. Absence 3. Presence 4. Gain 5. Loss
library(timecomptest) library(rgdal) library(raster) library(ggplot2) library(reshape) library(ggnewscale) library(dplyr) library(mice) library(magrittr)
This tutorial illustrates the concepts of timecomptest by using four dummy maps of land categories in 2000, 2001,2002, and 2003. Each map consists of nine pixels representing three categories: Forest, Urban, and Water.
The maps are available in "tif" format and included in the package. The first step is to read the raster files and put them in a data frame.
# Read the raster files from example data as raster brick. rasterstack <- brick(system.file("external/exampleraster.tif", package="timecomptest"))
# Make a data frame from the raster brick. df <- as.data.frame(rasterstack, xy = TRUE) df
Next, use the catTrajectory function to create two data frames. The catTrajectory function requires a data frame, a number representing no data, and a number representing the category of interest.
# Make a list of data frames. trajectory_data <- catTrajectory(dfRaster = df,noData = 0, category = 1) trajectory_data
Create a vector variable containing the pixel resolution of your raster files. Next, use the mapTrajectories function to create a map showing the trajectories of the category during the first and last time points.
# Create a vector of pixel resultion pix_size <- c(1000,1000) # Use the mapTrajectories function to create the map mapTrajectories(rasList = trajectory_data, pixelRes = pix_size, mapTitle = "MAP OF CHANGE", labx = "X(m)", laby = "Y(m)", axisFont = 1.5, titleFont = 1.3, legendFont = 1)
The stackedBarData function creates the data required to create the stacked bars for a category during the time series. To run the stackedBarData function, you must provide input from the catTrajectory function, a vector variable containing the time points of your raster files, and a vector variable containing the pixel resolution of your raster files.
# Create a vector variable containing the pixel resolution of your raster files time_points <- c(2000, 2001,2002,2003) # must be in chronological order # Create data for creating stacked bars stk_bar_data <- stackedBarData(cattrajectory = trajectory_data, timePoints = time_points,pixelSize = pix_size) stk_bar_data
The StackedTrajectories function creates a stacked bar for the categorical variable during the time series. The stacked bars show time intervals on the horizontal axis and change as square kilometers per year on the vertical axis. The time axis divides each time interval's stacked bar into gains and losses. The gains are above the time axis, and the losses are below the time axis. Also, the stacked bars show the net change for each time interval. The stacked bars show the net change using a green borderline.
# Create the stacked bars StackedTrajectories (Trajectories = stk_bar_data, Category = "FOREST", plotTitle = 10,legendText = 12, xAxisText = 12, yAxisText = 12,axisTitle = 14)
Pontius Jr, R. G. (2019). Component intensities to relate difference by category with difference overall. International Journal of Applied Earth Observation and Geoinformation, 77, 94–99. https://doi.org/10.1016/j.jag.2018.07.024
Pontius Jr, R. G. (2021). Metrics That Make a Difference: How to Analyze Change and Error. Springer Nature Switzerland AG.
Pontius Jr, R. G., Krithivasan, R., Sauls, L., Yan, Y., & Zhang, Y. (2017). Methods to summarize change among land categories across time intervals. Journal of Land Use Science, 12(4), 218–230. https://doi.org/10.1080/1747423X.2017.1338768
Pontius Jr, R. G., & Santacruz, A. (2014). Quantity, exchange, and shift components of difference in a square contingency table. International Journal of Remote Sensing, 35(21), 7543–7554. https://doi.org/10.1080/2150704X.2014.969814
Xie, Z., Pontius Jr, R. G., Huang, J., & Nitivattananon, V. (2020). Enhanced Intensity Analysis to Quantify Categorical Change and to Identify Suspicious Land Transitions: A Case Study of Nanchang, China. Remote Sensing, 12(20), 3323. https://doi.org/doi:10.3390/rs12203323
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.