README.md

timecomptest

Is an R package for analyzing the trajectories of a category during a time series.

Data

This tutorial illustrates the concepts of Time Components 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="timeComponents"))
# Make a data frame from the raster brick.
df <- as.data.frame(rasterstack, xy = TRUE)
df
#>        x      y exampleraster.1 exampleraster.2 exampleraster.3 exampleraster.4
#> 1 681900 781000               0               2               2               3
#> 2 681900 780000               2               3               2               3
#> 3 681900 779000               1               1               1               1
#> 4 681900 778000               1               3               3               3
#> 5 681900 777000               1               2               1               2
#> 6 681900 776000               3               2               2               1
#> 7 681900 775000               3               1               2               1
#> 8 681900 774000               2               1               3               2
#> 9 681900 773000               1               3               1               1

Calling the catTrajectory function

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
#> $combinedTrajectory
#>         x      y change
#> 1  681900 781000      0
#> 2  681900 780000      1
#> 8  681900 774000      1
#> 3  681900 779000      2
#> 9  681900 773000      2
#> 11 681900 778000      4
#> 21 681900 777000      4
#> 31 681900 776000      3
#> 4  681900 775000      3
#> 
#> $dfXYZBoolean
#>        x      y exampleraster.1 exampleraster.2 exampleraster.3 exampleraster.4
#> 2 681900 780000               0               0               0               0
#> 3 681900 779000               1               1               1               1
#> 4 681900 778000               1               0               0               0
#> 5 681900 777000               1               0               1               0
#> 6 681900 776000               0               0               0               1
#> 7 681900 775000               0               1               0               1
#> 8 681900 774000               0               1               0               0
#> 9 681900 773000               1               0               1               1

Calling the mapTrajectories function

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)

Calling the stackedBarData function

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
#> $NonetData
#>   X2 fromToTimepoints variable value
#> 1  1     2000 to 2001     gain     2
#> 2  1     2001 to 2002     gain     2
#> 3  1     2002 to 2003     gain     2
#> 4  1     2000 to 2001     loss    -3
#> 5  1     2001 to 2002     loss    -2
#> 6  1     2002 to 2003     loss    -1
#> 
#> $NetData
#>   X2 fromToTimepoints variable value
#> 1  1     2000 to 2001 net gain     0
#> 2  1     2002 to 2003 net gain     1
#> 3  1     2000 to 2001 net loss    -1
#> 4  1     2002 to 2003 net loss     0
#> 
#> $GrossGain
#> [1] 2
#> 
#> $GrossLoss
#> [1] -2
#> 
#> $lastTimeInterval
#> [1] "2000 TO 2003"
#> 
#> $numbTimeIntervals
#> [1] 3
#> 
#> $yaxisLable
#> [1] "Change (sqaure Kilometers per year)"

Calling the StackedTrajectories function

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.

References

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



bilintoh/timecomptest documentation built on Dec. 19, 2021, 9:42 a.m.