diff --git a/DESCRIPTION b/DESCRIPTION index 10b023a..230991e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,6 +38,7 @@ Depends: R (>= 4.1.0) Imports: dplyr, + ggplot2, jsonlite, rlang, sf, diff --git a/NAMESPACE b/NAMESPACE index 60ca6c9..f9bf2d8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,7 @@ export(get_pump_data) export(get_required_columns) export(get_sediment_trap_data) export(get_species_names) +export(map_distribution) export(reshape_forcis) export(select_columns) export(select_taxonomy) @@ -28,3 +29,8 @@ import(dplyr) import(rlang) import(tidyr) import(vroom) +importFrom(ggplot2,element_text) +importFrom(ggplot2,geom_sf) +importFrom(ggplot2,ggplot) +importFrom(ggplot2,theme) +importFrom(ggplot2,theme_void) diff --git a/R/forcis-package.R b/R/forcis-package.R index e5b057f..25519a9 100644 --- a/R/forcis-package.R +++ b/R/forcis-package.R @@ -6,6 +6,7 @@ #' @import rlang #' @import tidyr #' @import vroom +#' @importFrom ggplot2 ggplot geom_sf theme theme_void element_text # Imports: end ---- NULL diff --git a/R/map_distribution.R b/R/map_distribution.R new file mode 100644 index 0000000..54f1844 --- /dev/null +++ b/R/map_distribution.R @@ -0,0 +1,71 @@ +#' Plot a distribution map of FORCIS data +#' +#' @description +#' This function can be used to map FORCIS data. +#' +#' @param data a `data.frame`, i.e. a FORCIS dataset or the output of a +#' `filter_*()` function. +#' +#' @param col a `character` of length 1. The color of data on the map. +#' +#' @param ... other graphical parameters passed on to `geom_sf()`. +#' +#' @return A `ggplot` object. +#' +#' @export +#' +#' @examples +#' ## ADD EXAMPLE ---- + +map_distribution <- function(data, col = "red", ...) { + + ## Check data object ---- + + check_if_not_df(data) + + check_field_in_data(data, "site_lon_start_decimal") + check_field_in_data(data, "site_lat_start_decimal") + + + ## Convert data into sf object ----- + + data <- data[!is.na(data$"site_lon_start_decimal"), ] + data <- data[!is.na(data$"site_lat_start_decimal"), ] + + data_sf <- sf::st_as_sf(data, + coords = c("site_lon_start_decimal", + "site_lat_start_decimal"), + crs = sf::st_crs(4326)) + + + ## Project spatial objects into Robinson system ---- + + data_sf <- sf::st_transform(data_sf, sf::st_crs(crs_robinson())) + + + ## Map ---- + + ggplot() + + + ### Basemap ---- + + geom_sf(data = ne_oceans, fill = "#cdeafc", col = "#cdeafc", + linewidth = 0.10) + + geom_sf(data = ne_graticules, col = "#bae2fb", + linewidth = 0.10) + + geom_sf(data = ne_countries, fill = "#a6a6a6", col = "#b1b1b1", + linewidth = 0.10) + + geom_sf(data = ne_bbox, fill = NA, col = "#a6a6a6", + linewidth = 0.75) + + + + ### Data --- + + geom_sf(data = data_sf, col = col, ...) + + + + ### Theme ---- + + theme_void() + + theme(plot.title = element_text(hjust = 0.5)) +} diff --git a/codemeta.json b/codemeta.json index f3d3100..e957153 100644 --- a/codemeta.json +++ b/codemeta.json @@ -108,6 +108,18 @@ "sameAs": "https://CRAN.R-project.org/package=dplyr" }, "3": { + "@type": "SoftwareApplication", + "identifier": "ggplot2", + "name": "ggplot2", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=ggplot2" + }, + "4": { "@type": "SoftwareApplication", "identifier": "jsonlite", "name": "jsonlite", @@ -119,7 +131,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=jsonlite" }, - "4": { + "5": { "@type": "SoftwareApplication", "identifier": "rlang", "name": "rlang", @@ -131,7 +143,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=rlang" }, - "5": { + "6": { "@type": "SoftwareApplication", "identifier": "sf", "name": "sf", @@ -143,7 +155,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=sf" }, - "6": { + "7": { "@type": "SoftwareApplication", "identifier": "tidyr", "name": "tidyr", @@ -155,12 +167,12 @@ }, "sameAs": "https://CRAN.R-project.org/package=tidyr" }, - "7": { + "8": { "@type": "SoftwareApplication", "identifier": "utils", "name": "utils" }, - "8": { + "9": { "@type": "SoftwareApplication", "identifier": "vroom", "name": "vroom", @@ -174,7 +186,7 @@ }, "SystemRequirements": null }, - "fileSize": "1057.776KB", + "fileSize": "1059.228KB", "citation": [ { "@type": "SoftwareSourceCode", diff --git a/man/map_distribution.Rd b/man/map_distribution.Rd new file mode 100644 index 0000000..4dc0a75 --- /dev/null +++ b/man/map_distribution.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/map_distribution.R +\name{map_distribution} +\alias{map_distribution} +\title{Plot a distribution map of FORCIS data} +\usage{ +map_distribution(data, col = "red", ...) +} +\arguments{ +\item{data}{a \code{data.frame}, i.e. a FORCIS dataset or the output of a +\verb{filter_*()} function.} + +\item{col}{a \code{character} of length 1. The color of data on the map.} + +\item{...}{other graphical parameters passed on to \code{geom_sf()}.} +} +\value{ +A \code{ggplot} object. +} +\description{ +This function can be used to map FORCIS data. +} +\examples{ +## ADD EXAMPLE ---- +}