Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Mar 26, 2024
1 parent 098365f commit 09568f4
Show file tree
Hide file tree
Showing 26 changed files with 165 additions and 54 deletions.
19 changes: 19 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,25 @@ references:
given-names: Maximilian
year: '2024'
version: '>= 1.0.0'
- type: software
title: hexbin
abstract: 'hexbin: Hexagonal Binning Routines'
notes: Suggests
url: https://github.com/edzer/hexbin
repository: https://CRAN.R-project.org/package=hexbin
authors:
- family-names: Carr
given-names: Dan
email: dcarr@voxel.galaxy.gmu.edu
- family-names: Lewin-Koh
given-names: ported by Nicholas
- family-names: Maechler
given-names: Martin
email: maechler@stat.math.ethz.ch
- family-names: Sarkar
given-names: contains copies of lattice functions written by Deepayan
email: deepayan.sarkar@r-project.org
year: '2024'
- type: software
title: isoband
abstract: 'isoband: Generate Isolines and Isobands from Regularly Spaced Elevation
Expand Down
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Imports:
tibble (>= 3.0.0),
tidyr (>= 1.0.0)
Suggests:
hexbin,
isoband,
knitr,
lifecycle,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
body is still displayed transposed as of `dplyr::glimpse()`. See
`pillar::tbl_format_header()` and `pillar::tbl_format_footer()` for
examples.
- `as_sf()` converts a SpatVector to a sf object with an additional `tbl_df`
class for pretty printing.
- Tidy documentation.

# tidyterra 0.5.2
Expand Down
2 changes: 1 addition & 1 deletion R/as_coordinates.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' layers indicating the position of each cell (cell number, row and column).
#'
#' @return
#' A [tibble][tibble::tibble()] or a `SpatRaster` (if `as.raster = TRUE`) with
#' A [`tibble`][tibble::tibble()] or a `SpatRaster` (if `as.raster = TRUE`) with
#' the same number of rows (or cells) than the number of cells in `x`.
#'
#' When `as.raster = TRUE` the resulting `SpatRaster` has the same crs,
Expand Down
15 changes: 11 additions & 4 deletions R/as_sf.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#' Coerce a `SpatVector` to a \CRANpkg{sf} object
#' Coerce a `SpatVector` to a [`sf`][sf::st_sf] object
#'
#' @description
#'
#' [as_sf()] turns a `SpatVector` to \CRANpkg{sf}. This is a wrapper of
#' [sf::st_as_sf()] with the particularity that the groups created with
#' [as_sf()] turns a `SpatVector` to [`sf`][sf::st_sf] object. This is a wrapper
#' of [sf::st_as_sf()] with the particularity that the groups created with
#' [group_by.SpatVector()] are preserved.
#'
#' @return
#' A \CRANpkg{sf} object.
#' A [`sf`][sf::st_sf] object object with an additional `tbl_df` class, for
#' pretty printing method.
#'
#' @export
#'
Expand Down Expand Up @@ -59,6 +60,12 @@ as_sf <- function(x, ...) {
}
sfobj <- sf::st_as_sf(x, ...)

# Make a sf/tibble object
# https://github.com/r-spatial/sf/issues/951
# But boosting performance
template <- sf::st_as_sf(tibble::tibble(x = 1, y = 1), coords = c("x", "y"))
class(sfobj) <- class(template)

if (is_grouped_spatvector(x)) {
vars <- group_vars(x)
sfobj <- dplyr::group_by(sfobj, across_all_of(vars))
Expand Down
4 changes: 2 additions & 2 deletions R/as_spatraster.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @description
#'
#' `as_spatraster()` turns an existing data frame or [tibble][tibble::tibble()]
#' `as_spatraster()` turns an existing data frame or [`tibble`][tibble::tibble]
#' into a `SpatRaster`. This is a wrapper of [terra::rast()] S4 method for
#' signature `data.frame`.
#'
Expand All @@ -11,7 +11,7 @@
#'
#' @export
#'
#' @param x A [tibble][tibble::tibble()] or data frame.
#' @param x A [`tibble`][tibble::tibble()] or data frame.
#' @param xycols A vector of integers of length 2 determining the position of
#' the columns that hold the x and y coordinates.
#'
Expand Down
4 changes: 2 additions & 2 deletions R/as_spatvector.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#' @name as_spatvector
#' @rdname as_spatvector
#'
#' @param x A [tibble][tibble::tibble()], data frame or \CRANpkg{sf} object of
#' class [`sf`][sf::st_read()] or [`sfc`][sf::st_sfc()].
#' @param x A [`tibble`][tibble::tibble], data frame or \CRANpkg{sf} object of
#' class [`sf`][sf::st_sf] or [`sfc`][sf::st_sfc].
#'
#' @param ... additional arguments passed on to [terra::vect()].
#'
Expand Down
2 changes: 1 addition & 1 deletion R/as_tibble-Spat.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @name as_tibble.Spat
#'
#' @return
#' A [tibble][tibble::tibble()].
#' A [`tibble`][tibble::tibble()].
#'
#' @param x A `SpatRaster` created with [terra::rast()] or a `SpatVector`
#' created with [terra::vect()].
Expand Down
4 changes: 2 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ NULL
#'
#' @name hypsometric_tints_db
#' @format
#' A [tibble][tibble::tibble()] of `r nrow(hypsometric_tints_db)` rows and
#' A [`tibble`][tibble::tibble()] of `r nrow(hypsometric_tints_db)` rows and
#' `r ncol(hypsometric_tints_db)` columns. with the following fields:
#'
#' \describe{
Expand Down Expand Up @@ -128,7 +128,7 @@ NULL
#' Cross-blended hypsometric tints
#'
#' @description
#' A [tibble][tibble::tibble()] including the color map of
#' A [`tibble`][tibble::tibble()] including the color map of
#' `r length(unique(cross_blended_hypsometric_tints_db$pal))` gradient palettes.
#' All the palettes includes also a definition of colors limits in terms of
#' elevation (meters), that can be used with [ggplot2::scale_fill_gradientn()].
Expand Down
51 changes: 41 additions & 10 deletions R/fortify-Spat.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#' @family ggplot2.methods
#' @family coerce
#'
#' @return [fortify.SpatVector()] returns a \CRANpkg{sf} object and
#' [fortify.SpatRaster()] returns a \CRANpkg{tibble}. See **Methods**.
#' @return
#'
#' [fortify.SpatVector()] returns a [`sf`][sf::st_sf] object and
#' [fortify.SpatRaster()] returns a [`tibble`][tibble::tibble]. See **Methods**.
#'
#' @rdname fortify.Spat
#' @name fortify.Spat
Expand Down Expand Up @@ -47,14 +49,15 @@
#'
#' ## `SpatVector`
#'
#' Return a \CRANpkg{sf} object than can be used with [ggplot2::geom_sf()].
#' Return a [`sf`][sf::st_sf] object than can be used with [ggplot2::geom_sf()].
#'
#' @examples
#' \donttest{
#'
#' # Get a SpatRaster
#' r <- system.file("extdata/volcano2.tif", package = "tidyterra") %>%
#' terra::rast()
#' terra::rast() %>%
#' terra::project("EPSG:4326")
#'
#' fortified <- ggplot2::fortify(r)
#'
Expand All @@ -70,12 +73,40 @@
#' # You can now use a SpatRaster with raster, contours, etc.
#' library(ggplot2)
#'
#' # Use here the raster with resample
#' ggplot(r, maxcell = 10000) +
#' # Need the aes parameters
#' geom_raster(aes(x, y, fill = elevation)) +
#' # Adjust the coords
#' coord_equal()
#' # Use here the SpatRaster as a regular object
#' ggplot(r, aes(x, y, z = elevation)) +
#' stat_summary_hex(fun = mean, bins = 30, color = "white", linewidth = 0.1) +
#' scale_fill_gradientn(
#' colours = c(
#' "#80146E", "#804AA4", "#6771B8", "#379BC2",
#' "#3ABCBF", "#79D4B8", "white", "#FCEE88",
#' "#F8C34B", "#F7A72B", "#F4792D"
#' ),
#' values = c(
#' 0, 0.01, 0.02, 0.1, 0.3, 0.6, 0.8, 0.85,
#' 0.9, 0.95, 1
#' )
#' ) +
#' # Give spatial flavor to axis
#' coord_fixed(
#' xlim = c(174.761, 174.769),
#' ylim = c(-36.88, -36.872), expand = TRUE
#' ) +
#' scale_x_continuous(
#' name = "", n.breaks = 5,
#' labels = scales::label_number(
#' accuracy = 0.001,
#' suffix = "°"
#' )
#' ) +
#' scale_y_continuous(
#' name = "", n.breaks = 5,
#' labels = scales::label_number(
#' accuracy = 0.001,
#' suffix = "°"
#' )
#' )
#'
#'
#' # Or any other geom
#' ggplot(r) +
Expand Down
4 changes: 2 additions & 2 deletions R/geom_spatvector.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#'
#' These functions are wrappers of [ggplot2::geom_sf()] functions. Since a
#' [fortify.SpatVector()] method is provided, \CRANpkg{ggplot2} treat a
#' `SpatVector` in the same way that a \CRANpkg{sf} object. A side effect is
#' that you can use [ggplot2::geom_sf()] directly with `SpatVector` objects.
#' `SpatVector` in the same way that a [`sf`][sf::st_sf] object. A side effect
#' is that you can use [ggplot2::geom_sf()] directly with `SpatVector` objects.
#'
#' See [ggplot2::geom_sf()] for details on aesthetics, etc.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/scales_hypso.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
#' legend.key.width = rel(3),
#' legend.ticks = element_line(colour = "black", linewidth = 0.3),
#' legend.direction = "horizontal"
#' ) #'
#' )
#'
#' # Binned
#' ggplot() +
Expand Down
16 changes: 14 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.3.3 (2024-02-29 ucrt)",
"runtimePlatform": "R version 4.3.3 (2024-02-29)",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand Down Expand Up @@ -61,6 +61,18 @@
}
],
"softwareSuggestions": [
{
"@type": "SoftwareApplication",
"identifier": "hexbin",
"name": "hexbin",
"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=hexbin"
},
{
"@type": "SoftwareApplication",
"identifier": "isoband",
Expand Down Expand Up @@ -320,7 +332,7 @@
"SystemRequirements": null
},
"keywords": ["r", "terra", "ggplot-extension", "r-spatial", "rspatial", "r-package", "rstats", "rstats-package", "cran", "cran-r"],
"fileSize": "2266.445KB",
"fileSize": "2235.015KB",
"citation": [
{
"@type": "ScholarlyArticle",
Expand Down
2 changes: 1 addition & 1 deletion inst/schemaorg.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"runtimePlatform": "R version 4.3.3 (2024-02-29 ucrt)",
"runtimePlatform": "R version 4.3.3 (2024-02-29)",
"version": "0.5.2.9000"
}
2 changes: 1 addition & 1 deletion man/as_coordinates.Rd

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

9 changes: 5 additions & 4 deletions man/as_sf.Rd

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

4 changes: 2 additions & 2 deletions man/as_spatraster.Rd

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

4 changes: 2 additions & 2 deletions man/as_spatvector.Rd

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

2 changes: 1 addition & 1 deletion man/as_tibble.Spat.Rd

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

2 changes: 1 addition & 1 deletion man/cross_blended_hypsometric_tints_db.Rd

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

0 comments on commit 09568f4

Please sign in to comment.