Skip to content

Commit

Permalink
style: rename map_distribution() in ggmap_data()
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Feb 23, 2024
1 parent bf844ea commit 9aa079f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 15 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export(get_ocean_names)
export(get_required_columns)
export(get_species_names)
export(get_version_info)
export(map_distribution)
export(ggmap_data)
export(read_cpr_north_data)
export(read_cpr_south_data)
export(read_plankton_nets_data)
Expand Down
2 changes: 1 addition & 1 deletion R/map_distribution.R → R/ggmap_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @examples
#' ## ADD EXAMPLE ----

map_distribution <- function(data, col = "red", ...) {
ggmap_data <- function(data, col = "red", ...) {

data_sf <- data_to_sf(data)

Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ reference:
Functions to visualize FORCIS data
contents:
- geom_basemap
- map_distribution
- ggmap_data

- title: Utilities
desc: >
Expand Down
8 changes: 4 additions & 4 deletions man/map_distribution.Rd → man/ggmap_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ df <- data.frame(matrix(1:21, nrow = 1))
colnames(df) <- get_required_columns()


## map_distribution() ----
## ggmap_data() ----

test_that("Test map_distribution() for success", {
test_that("Test ggmap_data() for success", {

expect_silent({ gg <- map_distribution(df) })
expect_silent({ gg <- ggmap_data(df) })

expect_true("gg" %in% class(gg))
expect_true("ggplot" %in% class(gg))
Expand Down
75 changes: 70 additions & 5 deletions vignettes/data-visualization.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,80 @@ vignette: >

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
eval = FALSE,
echo = TRUE,
comment = "#>"
collapse = TRUE,
eval = TRUE,
echo = TRUE,
comment = "#>",
dpi = 150,
fig.align = "center",
out.width = "90%"
)
```

> **NOTE:** THIS IS A WORK IN PROGRESS.
The package `forcis` provides [a lot of functions](https://frbcesab.github.io/forcis/reference/index.html#visualization-tools) to visualize FORCIS data. This vignette shows how to use and customize these functions.


## Setup

First, let's import the required packages.

```{r setup}
library(forcis)
library(ggplot2)
```

Before going any further, we will download the latest version of the FORCIS database.

```{r 'download-db', eval=FALSE}
## Create a data/ folder ----
download_forcis_db(path = "data", version = NULL)
```

Work in progress...
The vignette will use the PUMP data of the FORCIS database. Let's import the latest release of the data.

```{r 'load-data', echo=FALSE}
file_name <- system.file(file.path("extdata", "FORCIS_pump_sample.csv"), package = "forcis")
pump_data <- vroom::vroom(file_name, delim = ";", show_col_types = FALSE)
```

```{r 'load-data-user', eval=FALSE}
pump_data <- read_pump_data(path = "data")
```

**NB** In this vignette, we use a subset of the PUMP data, not the whole dataset.


## World base map

The function `geom_basemap()` can be used to easily add World countries, oceans and bounding box to a `ggplot2` object.

```{r 'geom-basemap', echo=TRUE, fig.height=11, fig.width=20}
# World basemap ----
ggplot() +
geom_basemap()
```

These layers come from the [Natural Earth](https://www.naturalearthdata.com/) website and are defined in the [Robinson projection](https://epsg.io/54030).



## Map FORCIS data

The function `ggmap_data()` can be used to plot FORCIS data on a World map. Let's map the PUMP data.

```{r 'ggmap-raw-data', echo=TRUE, fig.height=11, fig.width=20}
# Map raw pump data ----
ggmap_data(pump_data)
```

This function works on the output of various functions available in the `forcis` package. For example:

```{r 'ggmap-filtered-data', echo=TRUE, fig.height=11, fig.width=20}
# Filter pump data ----
indian_pump_data <- filter_by_ocean(pump_data, ocean = "Indian Ocean")
# Map filtered data ----
ggmap_data(indian_pump_data)
```

0 comments on commit 9aa079f

Please sign in to comment.