Skip to content

kathasal/GRASP

Repository files navigation

GRASP

GRASP application aims to support the geoscience community by simplifying the grain size prediction process based on Partial Least Squares (PLS) regression, utilizing data such as geochemical composition (X-Ray Fluorescence: XRF) and density scanning data (Computed Tomography: CT).

Online access

The easiest and fastest way to access the tool is directly via a web browser at: https://kathasaluib.shinyapps.io/GRASP/.


Table of Contents

  1. Installation
  2. Usage
  3. Data
  4. Examples
  5. Dependencies
  6. References

Installation

To install the latest version of GRASP, use the remotes (Csárdi et al., 2024) package to install it from GitHub.

# Install remotes if not already installed
install.packages("remotes")

# Install GRASP from GitHub - when the repository is open
remotes::install_github("kathasal/GRASP")

# Install GRASP from GitHub - when the repository is private and the token is available
remotes::install_github("kathasal/GRASP", auth_token='token_name', upgrade='never')

The package requires several other packages: if you do not have them installed, they should install automatically.

Alternativelly, you can also install the application from the ZIP file available at Zenodo repository. The easiest way to do that is to use the devtools package (Wickham et al., 2022).

devtools::install_local("folder_path/GRASP-main.zip", upgrade = 'never')

Usage

After installation, load the package. You should see the welcome message as below.

library(GRASP)
## 
##   -------------------------------------------------------
##       Welcome to GRASP - GRAin Size Predictor!
## 
##       A workflow created to help predict mean grain size in sediment cores.
##       Developed by Katarzyna Hasal at UiB (University of Bergen).
## 
##       Please, make sure your version is up to date.
##       To get the latest version install from GitHub repository again.
## 
##       Useful Links:
##       - GitHub Repo (currently private): https://github.com/kathasal/GRASP
##       - online version: https://kathasaluib.shinyapps.io/GRASP/
## 
##   -------------------------------------------------------
## 

You can then access the functions and most importantly - the application provided by the package. To open it from your R console, simply type

GRASP()

and the application window should pop-up (see below). Please note that every action taken when running the GUI, will be recorded as lines of code in the console.


Data

To use the GUI, the user must provide their data in an Excel file (.xls or .xlsx). For an example of the required format, they can refer to the example dataset (GRASP_TestDataset.xlsx), located in the data-raw folder. The file contains grain size measurements, XRF- and CT-scanning results from sediment core AST-P2-18, originally published by van der Bilt et al. (2021) and used in the current study as a natural sediment application example.

The first sheet contains the training dataset with depth, measured grain size, and corresponding geochemical and CT variables. The second sheet contains the prediction dataset comprising depth intervals for which grain size predictions are to be made, along with the associated geochemical and CT variables.

Additionally, this dataset is accessible within the package. To access the samples that are measured for grain size (Grain size mean ($\mu$m) and Grain size (phi) for $\phi$ scale).

iceland
## # A tibble: 88 × 18
##    Unit   Material `Depth (cm)` `Grain size mean (µm)` `Grain size (phi)`     K
##    <chr>  <chr>           <dbl>                  <dbl>              <dbl> <dbl>
##  1 Unit 1 Organic          12.5                   27.2               5.20  57.4
##  2 Unit 1 Organic          22.5                   26.2               5.25  65  
##  3 Unit 1 Organic          32.5                   26.5               5.24  54.2
##  4 Unit 1 Organic          42.5                   23.9               5.39  48.9
##  5 Unit 1 Organic          52.5                   30.0               5.06  55.6
##  6 Unit 1 Organic          62.5                   24.4               5.36  39.8
##  7 Unit 1 Organic          72.5                   30.8               5.02  64  
##  8 Unit 1 Organic          82.5                   23.4               5.42  42.9
##  9 Unit 1 Organic          86.5                   26.5               5.24  64.1
## 10 Unit 1 Organic          88.5                   13.0               6.26 226. 
## # ℹ 78 more rows
## # ℹ 12 more variables: Ti <dbl>, Mn <dbl>, Fe <dbl>, Sr <dbl>, Zr <dbl>,
## #   `clr-K` <dbl>, `clr-Ti` <dbl>, `clr-Mn` <dbl>, `clr-Fe` <dbl>,
## #   `clr-Sr` <dbl>, `clr-Zr` <dbl>, `Density (CT greyscale)` <dbl>

And to see the high-resolution (every 0.5cm) scanning data.

iceland_predict
## # A tibble: 854 × 16
##    Unit   Material `Depth (cm)`     K    Ti    Mn    Fe    Sr    Zr `clr-K`
##    <chr>  <chr>           <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>   <dbl>
##  1 Unit 1 Organic           8.5 124.  2422.  666. 62432  329.  321.   -2.14
##  2 Unit 1 Organic           9   150.  2762.  753. 68191  315.  272.   -2.00
##  3 Unit 1 Organic           9.5 131.  2308.  648. 58609  299.  305    -2.05
##  4 Unit 1 Organic          10   113   1947.  542. 54787  226.  288.   -2.03
##  5 Unit 1 Organic          10.5  96   1934.  564. 57000  266.  335.   -2.25
##  6 Unit 1 Organic          11    79.5 1546.  422. 47223  204.  335.   -2.26
##  7 Unit 1 Organic          11.5  92.2 1544.  433. 47724  155.  315.   -2.06
##  8 Unit 1 Organic          12    87.5 1423   421. 43581  165.  286    -2.07
##  9 Unit 1 Organic          12.5  57.4 1062.  314. 41098  178.  302.   -2.34
## 10 Unit 1 Organic          13    71.5  959.  293. 36233  174   348.   -2.13
## # ℹ 844 more rows
## # ℹ 6 more variables: `clr-Ti` <dbl>, `clr-Mn` <dbl>, `clr-Fe` <dbl>,
## #   `clr-Sr` <dbl>, `clr-Zr` <dbl>, `Density (CT greyscale)` <dbl>

You can see the description of the datasets in R by typing in the console ?iceland and ?iceland_predict respectively.


Examples

For the details on how to use the application please refer to the user guide and video tutorial. The package also allows to use the functions independently from the console. As we aim to focus on the application, in this section, we will present only two functionalities. The demonstration is done on the test dataset, available within the package, described in the section above.

# Calculation of grain size in logarithmic phi scale, having measurements in µm
mu_scale_data <- iceland$`Grain size mean (µm)`
phi_scale_data <- calculate_phi_scale(mu_scale_data)

df <- data.frame("File values" = iceland$`Grain size (phi)`, 
                 "Calculated values" = phi_scale_data)
head(df)
##   File.values Calculated.values
## 1    5.200395              5.20
## 2    5.253574              5.25
## 3    5.236563              5.24
## 4    5.387379              5.39
## 5    5.057747              5.06
## 6    5.358932              5.36
# Calculation of CLR transform of compositional data
compositional <- names(iceland)[6:11]
compositional_data <- dplyr::select(iceland, all_of(compositional))

clr_transformed_data <- calculate_CLR(compositional_data)
head(clr_transformed_data)
##   calc_clr-K calc_clr-Ti calc_clr-Mn calc_clr-Fe calc_clr-Sr calc_clr-Zr
## 1  -2.330527   0.5884356  -0.6299782    4.243770  -1.2006920  -0.6710084
## 2  -2.370141   0.7283560  -0.6688395    4.095142  -1.0150993  -0.7694180
## 3  -2.441858   0.7382176  -0.8822945    3.950131  -0.9237262  -0.4404700
## 4  -2.372693   0.6237852  -0.7876984    4.020023  -1.1020487  -0.3813676
## 5  -2.452887   0.6977867  -0.6963276    4.212356  -1.1876003  -0.5733279
## 6  -2.601281   0.6893465  -0.6724720    4.028340  -0.9432658  -0.5006678

For more detailed documentation on each function, type ?function_name in R console.


Dependencies

GRASP is based on a number of revised R (R Core Team, 2023) packages. The creation of the application was aided by shiny (Chang et al., 2024), which provides the framework for building the app. Moreover, shinyjs (Attali, 2021) and bslib (Sievert et al., 2025) are used to improve and customize the user interface.

We rely on the pls (Liland et al., 2024) package to build Partial Least Squares regression models. readxl (Wickham & Bryan, 2023) and openxlsx (Schauberger & Walker, 2024) help to handle excel files, while ggplot2 (Wickham, Chang, et al., 2024), plotly (Sievert et al., 2024), DT (Xie et al., 2024), gridExtra (Auguie, 2017) and corrplot (Wei & Simko, 2024) serve for visualization purposes. Additionally, dplyr (Wickham et al., 2023), reshape2 (Wickham, 2020) and magrittr (Bache & Wickham, 2022) help with data transformation.

Finally, package development, testing and creation of documentation was possible with devtools (Wickham et al., 2022), roxygen2 (Wickham, Danenberg, et al., 2024), testthat (Wickham, 2024), knitr (Xie, 2024) and rmarkdown (Allaire et al., 2024) packages.


References

Allaire, J., Xie, Y., Dervieux, C., McPherson, J., Luraschi, J., Ushey, K., Atkins, A., Wickham, H., Cheng, J., Chang, W., & Iannone, R. (2024). Rmarkdown: Dynamic documents for r. https://github.com/rstudio/rmarkdown

Attali, D. (2021). Shinyjs: Easily improve the user experience of your shiny apps in seconds. https://deanattali.com/shinyjs/

Auguie, B. (2017). gridExtra: Miscellaneous functions for "grid" graphics. https://CRAN.R-project.org/package=gridExtra

Bache, S. M., & Wickham, H. (2022). Magrittr: A forward-pipe operator for r. https://magrittr.tidyverse.org

Chang, W., Cheng, J., Allaire, J., Sievert, C., Schloerke, B., Xie, Y., Allen, J., McPherson, J., Dipert, A., & Borges, B. (2024). Shiny: Web application framework for r. https://shiny.posit.co/

Csárdi, G., Hester, J., Wickham, H., Chang, W., Morgan, M., & Tenenbaum, D. (2024). Remotes: R package installation from remote repositories, including GitHub. https://remotes.r-lib.org

Liland, K. H., Mevik, B.-H., & Wehrens, R. (2024). Pls: Partial least squares and principal component regression. https://github.com/khliland/pls

R Core Team. (2023). R: A language and environment for statistical computing. R Foundation for Statistical Computing. https://www.R-project.org/

Schauberger, P., & Walker, A. (2024). Openxlsx: Read, write and edit xlsx files. https://ycphs.github.io/openxlsx/index.html

Sievert, C., Cheng, J., & Aden-Buie, G. (2025). Bslib: Custom bootstrap ’sass’ themes for shiny and rmarkdown. https://rstudio.github.io/bslib/

Sievert, C., Parmer, C., Hocking, T., Chamberlain, S., Ram, K., Corvellec, M., & Despouy, P. (2024). Plotly: Create interactive web graphics via plotly.js. https://plotly-r.com

van der Bilt, Willem G.M. et al. (2021). Late holocene canyon-carving floods in northern iceland were smaller than previously reported. Commun. Earth Environ., 2(86). https://doi.org/10.1038/s43247-021-00152-4

Wei, T., & Simko, V. (2024). Corrplot: Visualization of a correlation matrix. https://github.com/taiyun/corrplot

Wickham, H. (2020). reshape2: Flexibly reshape data: A reboot of the reshape package. https://github.com/hadley/reshape

Wickham, H. (2024). Testthat: Unit testing for r. https://testthat.r-lib.org

Wickham, H., & Bryan, J. (2023). Readxl: Read excel files. https://readxl.tidyverse.org

Wickham, H., Chang, W., Henry, L., Pedersen, T. L., Takahashi, K., Wilke, C., Woo, K., Yutani, H., Dunnington, D., & van den Brand, T. (2024). ggplot2: Create elegant data visualisations using the grammar of graphics. https://ggplot2.tidyverse.org

Wickham, H., Danenberg, P., Csárdi, G., & Eugster, M. (2024). roxygen2: In-line documentation for r. https://roxygen2.r-lib.org/

Wickham, H., François, R., Henry, L., Müller, K., & Vaughan, D. (2023). Dplyr: A grammar of data manipulation. https://dplyr.tidyverse.org

Wickham, H., Hester, J., Chang, W., & Bryan, J. (2022). Devtools: Tools to make developing r packages easier. https://devtools.r-lib.org/

Xie, Y. (2024). Knitr: A general-purpose package for dynamic report generation in r. https://yihui.org/knitr/

Xie, Y., Cheng, J., & Tan, X. (2024). DT: A wrapper of the JavaScript library DataTables. https://github.com/rstudio/DT

About

No description, website, or topics provided.

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors