litteR User Manual

  collapse = TRUE,
  echo = FALSE,
  comment = "#>"
options(knitr.kable.NA = "",  dplyr.width = Inf)


litteR is a user-friendly tool for analyzing litter data (e.g., beach litter data). The current version (r packageVersion("litteR")) contains routines for:

The focus of this version of litteR is to provide a a user-friendly, flexible, robust, transparent, and relatively simple tool for litter analysis. Although litteR is distributed as an R-package, experience with R is not required. If you need more information on how to install R, RStudio, and litteR, please consult our installation guide.

Litter data are count data. As has been illustrated in the histogram below (copied with permission from Hanke et al., 2019), litter data generally have skewed distributions. All procedures in litteR are based on robust statistical methods. They do not require distributional assumptions and are relatively robust for outliers.


This user guide consists of two parts. In the first part, the user interface is described, the second part provides details on the technicalities.

For applications with (a previous version of) litteR see Schulz et al. (2019). litteR is the successor of the Litter Analyst software (Schulz et al., 2017).

Loading the litteR-package

Before litteR can be used, it should be installed or updated in case you installed litteR before. See our installation guide fore details.

You need to install litteR only once, but you need to load this package each time you start RStudio.

The litteR-package should be loaded in RStudio before you can use it. This can be done by running the following code in the R-console or the RStudio-console:


A startup messsage appears that gives some essential instructions to start using litteR.

User interface

Create a new project {#create_new_project}

The easiest way to start working with litteR is to create an empty project directory. This directory can be filled with example and reference files by running:


in the RStudio-console. For more information on how to obtain and use RStudio, consult its website or read our installation guide.

The argument of function create_litter_project (i.e., the quoted part in parentheses) is an existing work directory on your computer. This can be any valid directory name with sufficient user privileges. Note for MS-Windows users: R requires forward slashes!

It is also possible to run create_litter_project() without an argument. In that case, a simple graphical user interface pops up for interactive directory selection.

Perform litter analysis

litteR can be started typing litter() in the RStudio console (see the figure below).


After entering litter(), a simple graphical user interface pops up for file selection. An example of a file selection dialogue is given below.



litteR needs three input files:

  1. a type file, which contains all litter types and litter groups that are allowed to use;
  2. a data file, which contains litter counts for each monitoring event.
  3. a settings file, which contains all settings needed to perform a litteR run;

These input files are described below.

Type file {#type_file}

The type file contains a list of all litter types that are allowed to use in the data file. It also indicates to which litter group each litter type belongs. Two example files, named 'types-ospar-materials.csv' and 'types-ospar-sup-fish-other.csv' are automatically generated when using the create_litter_project-function, a described earlier in this tutorial. A type file assigns each litter type (type_name) to one or more litter groups. The first 10 rows of 'types-ospar-sup-fish-other.csv are given in the table below.

path_package("litteR", "extdata", "types-ospar-sup-fish-other.csv") %>%
    read_csv(col_types = cols(
        type_name = col_character(),
        included = col_character(),
        SUP = col_character(),
        FISH = col_character(),
        PLASTIC = col_character()
    )) %>%
    slice(1:10) %>%
    kable(align = c("l", "r", "c", "c", "c", "c"))

The following columns are in this table:

The user may use one of the provided type files as a template for his own type file. litteR will use the type file that has been specified in the settings-file.

litteR performs regional aggregation at the group level. In order to perform regional aggregation at the type level (the columns in the data file), a group with only one or a few litter types of interest can be constructed in the type file, and then regionally aggregated by running litteR.

Data file {#data_file}

litteR supports a simple and flexible data format. It is similar to the OSPAR-format. The data are stored in so called wide format: each row refers to a single survey, each column to a single litter type or metadata. The table below gives an example of a small part (i.e., the upper left corner) of a data file.

add_dots <- function(x) {
    x_bot = x[1,]
    x_bot[1,] = ":"
    x <- bind_rows(x, x_bot)
    x_right <- x[,1]
    x_right[,1] <- "..."
    names(x_right) <- "Plastic..."
    x_right[nrow(x_right), 1] <- ":"
    bind_cols(x, x_right)

path_package("litteR", "extdata", "beach-litter-nl-2012-2017.csv") %>%
    read_csv(col_types = cols(.default = col_character())) %>%
    select(location_code, date, `Plastic: Yokes [1]`, `Plastic: Bags [2]`) %>%
    slice(1:5) %>%
    add_dots %>%
    kable(align = "llrrr")

The columns location_code and date are always required and define unique records (rows) with litter survey data for a specific date and location (e.g., a specific beach, or a location along a river). litteR will use these data to estimate statistics (as the median and trend) for each location_code.

Column location_code may contain location codes (as in the example above), but also full names like 'Bergen', 'Noordwijk', and 'La Grève des Courses'. Full names may be more clear when interpreting the results.

The date column gives the monitoring date in ISO format, i.e., YYYY-mm-dd (for example r Sys.Date(), to indicate r format(Sys.Date(), "%e %B %Y")). For convenience, the OSPAR-format (dd/mm/YYYY) is currently also supported (for example r format(Sys.Date(), "%d/%m/%Y"), to indicate r format(Sys.Date(), "%e %B %Y")).

Columns Plastic: Yokes [1], Plastic: Bags [2], ... contain the counts for specific litter types. Each litter type (column name) should be listed in the litter type file. Only litter types in the litter type file are valid column names. All column names that are not valid litter types are considered as optional metadata. These columns are ignored by litteR and do not affect the results.

There is one exception: the column region_code is optional and should be available when the locations (in column location_code) also need to be spatially aggregated. Each region_code is related to one or more location_code(s) that are part of that region.

In the data file below, one region_code (NL) is provided for all locations in location_code. Therefore, litteR will spatially aggregate the results for all locations (NL001 ... NL004) within the specified region (NL).

x_top <- path_package("litteR", "extdata", "beach-litter-nl-2012-2017.csv") %>%
    read_csv(col_types = cols(.default = col_character())) %>%
    select(region_code, location_code, date, `Plastic: Yokes [1]`, `Plastic: Bags [2]`) %>%
    slice_head(n = 3) 
x_bot <- path_package("litteR", "extdata", "beach-litter-nl-2012-2017.csv") %>%
    read_csv(col_types = cols(.default = col_character())) %>%
    select(region_code, location_code, date, `Plastic: Yokes [1]`, `Plastic: Bags [2]`) %>%
    slice_tail(n = 3) 
x_mid <- x_top[1,]
x_mid[1,] <- ":"
bind_rows(x_top, x_mid, x_bot) %>%
    add_dots %>%
    slice_head(n = nrow(.)-1) %>%
        .[4,ncol(.)] <- ":"
    } %>%
    kable(align = "lllrrr")

A data file can be constructed easily from existing litter files. As an example consider the OSPAR-format below:

path_package("litteR", "extdata", "beach-litter-nl-2012-2017.csv") %>%
    read_csv(col_types = cols(.default = col_character())) %>%
    mutate(Country = "Netherlands") %>%
        `Beach ID` = location_code,
        `Beach name` = location_name,
        `Survey date` = date,
        `Plastic: Yokes [1]`,
        `Plastic: Bags [2]`) %>%
    slice(1:3) %>%
    add_dots %>%
    kable(align = "llllrrr")

One can simply rename existing columns to the names required by litteR. This can be done with a spreadsheet program or a text editor. For instance, renaming Beach ID, Country and Survey date to respectively location_code, region_code, and date gives the following valid litteR format:

path_package("litteR", "extdata", "beach-litter-nl-2012-2017.csv") %>%
    read_csv(col_types = cols(.default = col_character())) %>%
    mutate(Country = "Netherlands") %>%
        location_code = location_code,
        `Beach name` = location_name,
        region_code = Country,
        date = date,
        `Plastic: Yokes [1]`,
        `Plastic: Bags [2]`) %>%
    slice(1:3) %>%
    add_dots %>%
    kable(align = "llllrrr")

Column Beach name is not recognized by litteR, and is therefore ignored.

As an alternative, one may also add new columns with valid litteR names to the data file and fill them with the contents of existing columns. See the example below:

path_package("litteR", "extdata", "beach-litter-nl-2012-2017.csv") %>%
    read_csv(col_types = cols(.default = col_character())) %>%
    mutate(Country = "Netherlands") %>%
        lc = location_code,
        region_code = Country,
        location_code = location_name,
        date = format(as.Date(date), "%d/%m/%Y"),
        `Beach ID` = lc,
        `Beach name` = location_name,
        `Survey date` = date) %>%
    select(-lc) %>%
    slice(1:3) %>%
    add_dots %>%
    kable(align = "l")

This can be done quite easily with a spreadsheet program. The original columns of the OSPAR-format (Beach ID, Beach name, Country, and Survey date) are ignored by litteR.

It is advised to use region_codes and location_codes that are easily recognized by the user. For instance, in the example above, location_code 'Bergen' is easier to interpret than location_code 'NL001'. Obviously, this choice does not affect the litteR-results.

Settings file {#settings_file}

The settings file contains all settings needed to run litteR. An example of the contents of a settings file is given in the figure below:

path_package("litteR", "extdata", "settings.yaml") %>%
    read_lines %>%
    cat(sep = "\n")

The settings-file contains the following entries:

Data Quality Control

All input files are validated by litteR. The following validation rules apply:

  1. all required columns (see above) should be available;
  2. the date format should be valid, i.e. preferably YYYY-mm-dd (ISO). For convenience, the OSPAR-date format (dd/mm/YYYY) is currently also supported;
  3. litter type names should be specified in the type file;
  4. litter counts in the data file are natural numbers (ISO 80000-2). However, in some cases data files contain real numbers due to preprocessing. Think about normalizing survey lengths to a common length. Although litteR prefers natural numbers, real numbers are also allowed for convenience. In case non-natural numbers are found, litteR will give a warning but will continue the analysis.;
  5. all records should be unique, duplicated records will be removed with a warning;
  6. all cells should be filled with the appropriate data type (numbers, text or dates).
  7. the data file should be a comma-separated values file (CSV), i.e., a text file where the columns are separated by commas (,) and not by spaces, semicolons (;) or tabs.


litteR produces three output files:

  1. a report, containing all analysis results
  2. a CSV-file, containing all beach litter statistics
  3. a log-file, containing all log data.

For convenience, all input and output files are stored as a snapshot in a directory with names like litteR-results-20210904T221809, where the final part of the name is a timestamp.


litteR produces an HTML-report that can best be viewed with modern web browsers like Mozilla FireFox, Google Chrome, or Safari. These browsers are freely available from the internet.

The filename of each report starts with 'litter-results', followed by a timestamp: YYYYmmddTHHMMSS and the extension html. For example: litteR-results-20210904T221809.html

This section briefly describes each section in the HTML-report


This section gives a summary of the settings in the settings file.

Data Quality Control

In this section (potential) problems in the input files are reported. These problems are also stored in the log file.

Outlier analysis

For each location_code in the data file, adjusted boxplots are given of the total count for the detection of outliers. Outliers are given as dots (if any) in adjusted box-and-whisker plots. Adjusted boxplots are more suitable for outlier detection in case of skewed distributions than traditional box plots. An example of these box-and-whisker plots are given below.


Descriptive statistics {#descriptive_statistics}

For each location_code and group/type name, the following statistics are estimated:

These statistics will be estimated for litter types with the greatest counts making up a given percentage of the total count for each location and for all groups specified in the type file. This percentage needs to be provided as percentage_total_count in the settings file.

The descriptive statistics for the litter types and groups are stored in a CSV-file with a name starting with litteR-results and ending with a timestamp. The statistics for litter groups are also printed as a table and shown as bar plots in the report: one plot for each location_code column of the data file. An example is given in the figure below. If you want other groups, or only a subset of groups, you should modify the type file.

In addition to the statistics given above, the top 10 of litter types for each location is given in a table and as a figure. This top 10 is based on median litter counts.


Regional descriptive statistics

When the data file contains column region_code, the data for the location_codes in that region are spatially aggregated in a stepwise fashion:

  1. First a (summary) statistic is estimated for each location (location_code) within that region (region_code).
  2. Next, the same statistic is computed for the results in step 1 to obtain the regional statistic for that region.

Note that these statistics are so called intra-block statistics, i.e., data from individual location_codes are not merged.

The summary statistics are:

In addition to the regional statistics given above, the top 10 of litter types for each region is given in a table and as a figure. This top 10 is based on median litter counts.

Trend analysis

For each location_code, and the type names and group codes specified in the settings file, trends are estimated by means of the Theil-Sen slope estimator: a robust non-parametric estimator of slope (counts / year). The significance of the estimated slopes is tested by means of the Mann-Kendall test. The Mann-Kendall test is a non-parametric test and as such does not make distributional assumptions on the data.

The figure below gives examples of trend plots for total count (TC), single use plastics (SUP), and plastic bags at the beach of Terschelling (The Netherlands). In each plot, the black dots are the observations, the thin gray line segments connect the dots and guide the eye, and the red line is the Theil-Sen slope.


Regional trend analysis

For each region_code, and the type names and group codes specified in the settings file, the following statistics have been estimated:

A p-value less than an a priori specified significance level (e.g., often α = 0.05), indicates a significant trend. If the p-value is greater than this significance level, we can't say that there is no trend. We can only conclude that our data do not show evidence for a significant trend (due to lack of data, noise, etc.).

The Regional Kendall test is a non-parametric test and as such does not make distributional assumptions on the data.

An example of a regional trend is given in the figure below:


Statistical summary file

In addition to a report, a results file (CSV-format) with descriptive statistics and the main trend results for each location_code is produced. An example of such a table is given below. See Section descriptive statistics for more details.

path("tab", "litteR-results-20210904T221809.csv") %>%
    read_csv(col_types = cols(.default = col_character())) %>%
    slice(1:10) %>%

Log-file {#log_file}

litteR's log-file is very helpful to understand warnings and error messages. The log-file stores the description of all data analysis steps in chronological order. Part of a log-file is given below. The complete log-file is given in the [appendix].

path("tab", "litteR-log-20210904T221809.log") %>%
    read_lines %>%
    head(20) %>%
    paste0(collapse = "\n") %>%

Each line contains a single log-event and always has the following format:

  1. timestamp;
  2. type of log event: INFO for informative messages, WARN for warnings, ERROR for errors;
  3. a log message.


The runtime error messages and the log file should provide you with clear information about errors in the data file and settings, and about warnings (points of attention). For additional information you can consult the points below.


Gilbert, R.O., 1987. Statistical Methods for Environmental Pollution Monitoring. Van Nostrand Reinhold. 320 pp

Hanke G., Walvoort D., van Loon W., Addamo A.M., Brosich A., del Mar Chaves Montero M., Molina Jack M.E., Vinci M., Giorgetti A., EU Marine Beach Litter Baselines, EUR 30022 EN, Publications Office of the European Union, Luxemburg, 2019, ISBN 978-92-76-14243-0,, JRC114129.

Schulz, M., van Loon, W., Fleet, D. M., Baggelaar, P., & van der Meulen, E. (2017). OSPAR standard method and software for statistical analysis of beach litter data. Marine pollution bulletin, 122(1-2), 166-175.

Schulz, Marcus, Dennis J.J. Walvoort, Jon Barry, David M. Fleet, Willem M.G.M. van Loon, 2019. Baseline and power analyses for the assessment of beach litter reductions in the European OSPAR region. Environmental Pollution 248:555-564.

Van Belle, G., J.P. Hughes, 1984. Nonparametric Tests for Trend in Water Quality. Water Resources Research 20: 127-136.


Example of a log-file produced by litteR.

path("tab", "litteR-log-20210904T221809.log") %>%
    read_lines %>%
    paste0(collapse = "\n") %>%

Try the litteR package in your browser

Any scripts or data that you put into this service are public.

litteR documentation built on Aug. 27, 2022, 1:05 a.m.