diff --git a/BS5/gitdevr.css b/BS5/gitdevr.css index 3532e319..9cb8beac 100644 --- a/BS5/gitdevr.css +++ b/BS5/gitdevr.css @@ -31,7 +31,7 @@ main img { } .navbar .text-muted { - color: #6A788A !important; + color: #c6ced8 !important; } .navbar-brand:hover, diff --git a/BS5/gitdevr.min.css b/BS5/gitdevr.min.css index 3b1fef5e..da34497e 100644 --- a/BS5/gitdevr.min.css +++ b/BS5/gitdevr.min.css @@ -3,4 +3,4 @@ * Licensed under MIT * Beautify: https://www.freeformatter.com/css-beautifier.html * Minify: https://www.freeformatter.com/css-minifier.html -*/main img{margin-left:auto;margin-right:auto}.caption,.figure{color:#6a788a;margin-left:auto;margin-right:auto;margin-top:.5rem;font-size:85%;width:100%}.navbar{font-family:'Inter Tight',Roboto}.navbar-brand{font-weight:800;color:#fff}.navbar .text-muted{color:#6a788a !important}.navbar-brand:hover,.navbar-brand:focus{color:#fff}#navbar{font-weight:800}#navbar .dropdown-menu{background-color:#212529 !important}#navbar .dropdown-menu .dropdown-item{color:#fff !important;font-weight:800}#navbar .nav-link:hover,#navbar .nav-link:focus{color:#6a788a !important}#navbar .dropdown-menu .dropdown-item:hover,#navbar .dropdown-menu .dropdown-item:focus{color:#6a788a !important;background-color:#f8f9fa}.navbar-toggler{border:0}.algolia-autocomplete .aa-dropdown-menu{color:#22272e}footer{width:100vw;position:relative;left:50%;right:50%;margin-left:-50vw;margin-right:-50vw;background-color:#212529 !important;color:#8b949e;margin-bottom:0;font-family:'Inter Tight',Roboto;font-weight:700}footer a{color:#58a6ff;text-decoration:none}footer a:hover,footer a:focus{color:#8b949e}footer .pkgdown-footer-right{margin-right:auto;padding-right:1.25rem}footer .pkgdown-footer-left{margin-left:auto;padding-left:1.25rem}@media screen and (max-width:576px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{margin-right:.75rem;margin-left:.75rem;padding-left:12px;padding-right:12px}}@media(max-width:768px) and (min-width:576px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{max-width:270px}}@media(max-width:992px) and (min-width:768px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{max-width:360px}}@media(max-width:1200px) and (min-width:992px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{max-width:480px}}@media(max-width:1400px) and (min-width:1200px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{max-width:570px}}@media(min-width:1400px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{max-width:660px}}img.logo{display:none}.template-home img.logo{display:inline}blockquote{border-left:solid #0969da !important;font-size:115%}.pkg{font-weight:bold}code a:any-link{text-decoration:underline;text-decoration-color:#6c757d}a>code{text-decoration:underline;color:#e83e8c}code{font-size:87.5%;color:#e83e8c;word-wrap:break-word}.template-reference-topic dt code{font-weight:700;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);padding:0;border-radius:0}pre{background-color:#f4f4f5}pre code{color:#212529}pre code span.al{color:#a00}pre code span.an{color:#228b22}pre code span.ch{color:#cd5555}pre code span.cn{color:#658b00}pre code span.co{color:#228b22}pre code span.cv{color:#228b22}pre code span.do{color:#228b22}pre code span.dv{color:#b452cd}pre code span.er{color:#a00}pre code span.fl{color:#b452cd}pre code span.fu{color:#212529}pre code span.in{color:#555}pre code span.kw{color:#8b008b;font-weight:bold}pre code span.ot{color:#cb6c20}pre code span.sc{color:#cd5555}pre code span.ss{color:#cd5555}pre code span.st{color:#cd5555}pre code span.va{color:#212529}pre code span.vs{color:#cd5555}pre code span.wa{color:#a00} +*/main img{margin-left:auto;margin-right:auto}.caption,.figure{color:#6a788a;margin-left:auto;margin-right:auto;margin-top:.5rem;font-size:85%;width:100%}.navbar{font-family:'Inter Tight',Roboto}.navbar-brand{font-weight:800;color:#fff}.navbar .text-muted{color:#c6ced8 !important}.navbar-brand:hover,.navbar-brand:focus{color:#fff}#navbar{font-weight:800}#navbar .dropdown-menu{background-color:#212529 !important}#navbar .dropdown-menu .dropdown-item{color:#fff !important;font-weight:800}#navbar .nav-link:hover,#navbar .nav-link:focus{color:#6a788a !important}#navbar .dropdown-menu .dropdown-item:hover,#navbar .dropdown-menu .dropdown-item:focus{color:#6a788a !important;background-color:#f8f9fa}.navbar-toggler{border:0}.algolia-autocomplete .aa-dropdown-menu{color:#22272e}footer{width:100vw;position:relative;left:50%;right:50%;margin-left:-50vw;margin-right:-50vw;background-color:#212529 !important;color:#8b949e;margin-bottom:0;font-family:'Inter Tight',Roboto;font-weight:700}footer a{color:#58a6ff;text-decoration:none}footer a:hover,footer a:focus{color:#8b949e}footer .pkgdown-footer-right{margin-right:auto;padding-right:1.25rem}footer .pkgdown-footer-left{margin-left:auto;padding-left:1.25rem}@media screen and (max-width:576px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{margin-right:.75rem;margin-left:.75rem;padding-left:12px;padding-right:12px}}@media(max-width:768px) and (min-width:576px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{max-width:270px}}@media(max-width:992px) and (min-width:768px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{max-width:360px}}@media(max-width:1200px) and (min-width:992px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{max-width:480px}}@media(max-width:1400px) and (min-width:1200px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{max-width:570px}}@media(min-width:1400px){footer .pkgdown-footer-right,footer .pkgdown-footer-left{max-width:660px}}img.logo{display:none}.template-home img.logo{display:inline}blockquote{border-left:solid #0969da !important;font-size:115%}.pkg{font-weight:bold}code a:any-link{text-decoration:underline;text-decoration-color:#6c757d}a>code{text-decoration:underline;color:#e83e8c}code{font-size:87.5%;color:#e83e8c;word-wrap:break-word}.template-reference-topic dt code{font-weight:700;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);padding:0;border-radius:0}pre{background-color:#f4f4f5}pre code{color:#212529}pre code span.al{color:#a00}pre code span.an{color:#228b22}pre code span.ch{color:#cd5555}pre code span.cn{color:#658b00}pre code span.co{color:#228b22}pre code span.cv{color:#228b22}pre code span.do{color:#228b22}pre code span.dv{color:#b452cd}pre code span.er{color:#a00}pre code span.fl{color:#b452cd}pre code span.fu{color:#212529}pre code span.in{color:#555}pre code span.kw{color:#8b008b;font-weight:bold}pre code span.ot{color:#cb6c20}pre code span.sc{color:#cd5555}pre code span.ss{color:#cd5555}pre code span.st{color:#cd5555}pre code span.va{color:#212529}pre code span.vs{color:#cd5555}pre code span.wa{color:#a00} diff --git a/CODE_OF_CONDUCT.html b/CODE_OF_CONDUCT.html index d71606d1..0353d2c2 100644 --- a/CODE_OF_CONDUCT.html +++ b/CODE_OF_CONDUCT.html @@ -48,7 +48,7 @@
diff --git a/CONTRIBUTING.html b/CONTRIBUTING.html index d75901bc..57604c35 100644 --- a/CONTRIBUTING.html +++ b/CONTRIBUTING.html @@ -48,7 +48,7 @@
diff --git a/LICENSE.html b/LICENSE.html index 2b921878..b9c06095 100644 --- a/LICENSE.html +++ b/LICENSE.html @@ -48,7 +48,7 @@ @@ -173,7 +173,7 @@

Session info#> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz UTC -#> date 2025-01-07 +#> date 2025-01-08 #> pandoc 3.1.11 @ C:/HOSTED~1/windows/pandoc/31F387~1.11/x64/PANDOC~1.11/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── @@ -233,7 +233,7 @@

Session info#> tibble 3.2.1 2023-03-20 [1] RSPM #> tidyr 1.3.1 2024-01-24 [1] RSPM #> tidyselect 1.2.1 2024-03-11 [1] RSPM -#> tidyterra * 0.6.2 2025-01-07 [1] local +#> tidyterra * 0.6.2 2025-01-08 [1] local #> units 0.8-5 2023-11-28 [1] RSPM #> vctrs 0.6.5 2023-12-01 [1] RSPM #> withr 3.0.2 2024-10-28 [1] RSPM diff --git a/articles/tidyterra.html b/articles/tidyterra.html index 2d45cd4a..a70f7832 100644 --- a/articles/tidyterra.html +++ b/articles/tidyterra.html @@ -94,7 +94,7 @@

Diego

2023-07-18

- Source:
vignettes/tidyterra.Rmd + Source: vignettes/tidyterra.Rmd
tidyterra.Rmd

diff --git a/articles/welcome.html b/articles/welcome.html index 09c6e584..237e1d38 100644 --- a/articles/welcome.html +++ b/articles/welcome.html @@ -86,7 +86,7 @@

First steps with the tidyterra package

- Source: vignettes/welcome.Rmd + Source: vignettes/welcome.Rmd
welcome.Rmd
diff --git a/articles/wild.html b/articles/wild.html index 940c6982..7d6f36a2 100644 --- a/articles/wild.html +++ b/articles/wild.html @@ -90,7 +90,7 @@

tidyterra in the wild

- Source: vignettes/articles/wild.Rmd + Source: vignettes/articles/wild.Rmd
wild.Rmd
diff --git a/authors.html b/authors.html index ff1ebb15..2eb4a74f 100644 --- a/authors.html +++ b/authors.html @@ -69,7 +69,7 @@

Authors

Citation

-

Source: inst/CITATION

+

Source: inst/CITATION

Hernangómez D (2023). “Using the tidyverse with terra objects: the tidyterra package.” diff --git a/news/index.html b/news/index.html index 8b12900d..02f30394 100644 --- a/news/index.html +++ b/news/index.html @@ -48,11 +48,11 @@

-

tidyterra 0.6.2

+

tidyterra 0.6.2

CRAN release: 2025-01-08

  • Add (limited) support for SpatGraticule (see terra::graticule()) #155.
  • New arguments in geom_spatraster_rgb(): stretch and zlim. See terra::plotRGB() for clarification.
  • diff --git a/pkgdown.yml b/pkgdown.yml index a895d8c4..8c49928c 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -7,7 +7,7 @@ articles: tidyterra: tidyterra.html welcome: welcome.html articles/wild: wild.html -last_built: 2025-01-07T14:06Z +last_built: 2025-01-08T10:50Z urls: reference: https://dieghernan.github.io/tidyterra/reference article: https://dieghernan.github.io/tidyterra/articles diff --git a/reference/arrange.SpatVector.html b/reference/arrange.SpatVector.html index a70c1487..fa14b1e0 100644 --- a/reference/arrange.SpatVector.html +++ b/reference/arrange.SpatVector.html @@ -50,7 +50,7 @@
    diff --git a/reference/as_coordinates.html b/reference/as_coordinates.html index a4590ad4..85121cb2 100644 --- a/reference/as_coordinates.html +++ b/reference/as_coordinates.html @@ -50,7 +50,7 @@
    diff --git a/reference/as_sf.html b/reference/as_sf.html index dccf5bf5..4333cab0 100644 --- a/reference/as_sf.html +++ b/reference/as_sf.html @@ -52,7 +52,7 @@
    diff --git a/reference/as_spatraster.html b/reference/as_spatraster.html index 55de8752..626d1e39 100644 --- a/reference/as_spatraster.html +++ b/reference/as_spatraster.html @@ -52,7 +52,7 @@
    diff --git a/reference/as_spatvector.html b/reference/as_spatvector.html index a853571d..88b4b045 100644 --- a/reference/as_spatvector.html +++ b/reference/as_spatvector.html @@ -50,7 +50,7 @@
    diff --git a/reference/as_tibble.Spat.html b/reference/as_tibble.Spat.html index 86516c31..c1a60946 100644 --- a/reference/as_tibble.Spat.html +++ b/reference/as_tibble.Spat.html @@ -48,7 +48,7 @@
    diff --git a/reference/autoplot.Spat.html b/reference/autoplot.Spat.html index bb795bc2..ad3d217f 100644 --- a/reference/autoplot.Spat.html +++ b/reference/autoplot.Spat.html @@ -50,7 +50,7 @@
    diff --git a/reference/bind_cols.SpatVector.html b/reference/bind_cols.SpatVector.html index 73a2414b..b2155b7a 100644 --- a/reference/bind_cols.SpatVector.html +++ b/reference/bind_cols.SpatVector.html @@ -58,7 +58,7 @@
    diff --git a/reference/bind_rows.SpatVector.html b/reference/bind_rows.SpatVector.html index 2e9ae7e4..f3cba666 100644 --- a/reference/bind_rows.SpatVector.html +++ b/reference/bind_rows.SpatVector.html @@ -52,7 +52,7 @@
    diff --git a/reference/compare_spatrasters.html b/reference/compare_spatrasters.html index 06d030aa..0453909b 100644 --- a/reference/compare_spatrasters.html +++ b/reference/compare_spatrasters.html @@ -56,7 +56,7 @@
    diff --git a/reference/count.SpatVector.html b/reference/count.SpatVector.html index 3a262f02..33c36fff 100644 --- a/reference/count.SpatVector.html +++ b/reference/count.SpatVector.html @@ -60,7 +60,7 @@
    diff --git a/reference/cross_blended_hypsometric_tints_db.html b/reference/cross_blended_hypsometric_tints_db.html index e3903d26..edd8e7c7 100644 --- a/reference/cross_blended_hypsometric_tints_db.html +++ b/reference/cross_blended_hypsometric_tints_db.html @@ -54,7 +54,7 @@
    diff --git a/reference/distinct.SpatVector.html b/reference/distinct.SpatVector.html index edfc2edc..1d00b476 100644 --- a/reference/distinct.SpatVector.html +++ b/reference/distinct.SpatVector.html @@ -48,7 +48,7 @@
    diff --git a/reference/drop_na.Spat.html b/reference/drop_na.Spat.html index b1917342..57a0de67 100644 --- a/reference/drop_na.Spat.html +++ b/reference/drop_na.Spat.html @@ -62,7 +62,7 @@
    diff --git a/reference/fill.SpatVector.html b/reference/fill.SpatVector.html index 93f99c79..4d3d539e 100644 --- a/reference/fill.SpatVector.html +++ b/reference/fill.SpatVector.html @@ -52,7 +52,7 @@
    diff --git a/reference/filter-joins.SpatVector.html b/reference/filter-joins.SpatVector.html index 2d4b093f..8bdf2cc3 100644 --- a/reference/filter-joins.SpatVector.html +++ b/reference/filter-joins.SpatVector.html @@ -60,7 +60,7 @@
    diff --git a/reference/filter.Spat.html b/reference/filter.Spat.html index ca65e353..c7539444 100644 --- a/reference/filter.Spat.html +++ b/reference/filter.Spat.html @@ -62,7 +62,7 @@
    diff --git a/reference/fortify.Spat.html b/reference/fortify.Spat.html index ae492fdf..6b420f56 100644 --- a/reference/fortify.Spat.html +++ b/reference/fortify.Spat.html @@ -50,7 +50,7 @@
    diff --git a/reference/geom_spat_contour.html b/reference/geom_spat_contour.html index 7f288e12..cebc519e 100644 --- a/reference/geom_spat_contour.html +++ b/reference/geom_spat_contour.html @@ -60,7 +60,7 @@
    diff --git a/reference/geom_spatraster.html b/reference/geom_spatraster.html index 57d6f06a..e50dc004 100644 --- a/reference/geom_spatraster.html +++ b/reference/geom_spatraster.html @@ -62,7 +62,7 @@
    diff --git a/reference/geom_spatraster_rgb.html b/reference/geom_spatraster_rgb.html index ed774edb..b1e44f8f 100644 --- a/reference/geom_spatraster_rgb.html +++ b/reference/geom_spatraster_rgb.html @@ -56,7 +56,7 @@
    diff --git a/reference/ggspatvector.html b/reference/ggspatvector.html index 16bdd40b..0e555829 100644 --- a/reference/ggspatvector.html +++ b/reference/ggspatvector.html @@ -50,7 +50,7 @@
    diff --git a/reference/glimpse.Spat.html b/reference/glimpse.Spat.html index 652bc1c3..8c2c7958 100644 --- a/reference/glimpse.Spat.html +++ b/reference/glimpse.Spat.html @@ -52,7 +52,7 @@
    diff --git a/reference/grass_db.html b/reference/grass_db.html index e448cb80..8e19e5b9 100644 --- a/reference/grass_db.html +++ b/reference/grass_db.html @@ -54,7 +54,7 @@
    diff --git a/reference/group-by.SpatVector.html b/reference/group-by.SpatVector.html index 87e85229..60e2883a 100644 --- a/reference/group-by.SpatVector.html +++ b/reference/group-by.SpatVector.html @@ -52,7 +52,7 @@
    diff --git a/reference/group_data.SpatVector.html b/reference/group_data.SpatVector.html index b273d476..ae786fed 100644 --- a/reference/group_data.SpatVector.html +++ b/reference/group_data.SpatVector.html @@ -82,7 +82,7 @@
    diff --git a/reference/hypsometric_tints_db.html b/reference/hypsometric_tints_db.html index f311463e..9a31ef38 100644 --- a/reference/hypsometric_tints_db.html +++ b/reference/hypsometric_tints_db.html @@ -54,7 +54,7 @@
    diff --git a/reference/is_grouped_spatvector.html b/reference/is_grouped_spatvector.html index c903b1b6..aad35717 100644 --- a/reference/is_grouped_spatvector.html +++ b/reference/is_grouped_spatvector.html @@ -58,7 +58,7 @@
    diff --git a/reference/is_regular_grid.html b/reference/is_regular_grid.html index bf484c89..0146f10f 100644 --- a/reference/is_regular_grid.html +++ b/reference/is_regular_grid.html @@ -52,7 +52,7 @@
    diff --git a/reference/mutate-joins.SpatVector.html b/reference/mutate-joins.SpatVector.html index 4e4061e9..0329c136 100644 --- a/reference/mutate-joins.SpatVector.html +++ b/reference/mutate-joins.SpatVector.html @@ -54,7 +54,7 @@
    diff --git a/reference/mutate.Spat.html b/reference/mutate.Spat.html index 12eab98c..b1d91edc 100644 --- a/reference/mutate.Spat.html +++ b/reference/mutate.Spat.html @@ -54,7 +54,7 @@
    diff --git a/reference/pipe.html b/reference/pipe.html index edd2b7a3..fdf4722f 100644 --- a/reference/pipe.html +++ b/reference/pipe.html @@ -48,7 +48,7 @@
    diff --git a/reference/pivot_longer.SpatVector.html b/reference/pivot_longer.SpatVector.html index 31ecfd1d..96fda55a 100644 --- a/reference/pivot_longer.SpatVector.html +++ b/reference/pivot_longer.SpatVector.html @@ -54,7 +54,7 @@
    diff --git a/reference/pivot_wider.SpatVector.html b/reference/pivot_wider.SpatVector.html index 6b385f4f..b1f38452 100644 --- a/reference/pivot_wider.SpatVector.html +++ b/reference/pivot_wider.SpatVector.html @@ -52,7 +52,7 @@
    diff --git a/reference/princess_db.html b/reference/princess_db.html index 5aede2b1..24654182 100644 --- a/reference/princess_db.html +++ b/reference/princess_db.html @@ -50,7 +50,7 @@
    diff --git a/reference/pull.Spat.html b/reference/pull.Spat.html index 8199f7c0..957619fe 100644 --- a/reference/pull.Spat.html +++ b/reference/pull.Spat.html @@ -58,7 +58,7 @@
    diff --git a/reference/pull_crs.html b/reference/pull_crs.html index be9632a1..90cbdf2e 100644 --- a/reference/pull_crs.html +++ b/reference/pull_crs.html @@ -60,7 +60,7 @@
    diff --git a/reference/reexports.html b/reference/reexports.html index 754986fd..561b5304 100644 --- a/reference/reexports.html +++ b/reference/reexports.html @@ -86,7 +86,7 @@
    diff --git a/reference/relocate.Spat.html b/reference/relocate.Spat.html index 206167fd..fac33fd1 100644 --- a/reference/relocate.Spat.html +++ b/reference/relocate.Spat.html @@ -52,7 +52,7 @@
    diff --git a/reference/rename.Spat.html b/reference/rename.Spat.html index 48001feb..1c3a57a5 100644 --- a/reference/rename.Spat.html +++ b/reference/rename.Spat.html @@ -52,7 +52,7 @@
    diff --git a/reference/replace_na.Spat.html b/reference/replace_na.Spat.html index e6693239..2de814bc 100644 --- a/reference/replace_na.Spat.html +++ b/reference/replace_na.Spat.html @@ -48,7 +48,7 @@
    diff --git a/reference/rowwise.SpatVector.html b/reference/rowwise.SpatVector.html index bfd78efd..6f90eeab 100644 --- a/reference/rowwise.SpatVector.html +++ b/reference/rowwise.SpatVector.html @@ -58,7 +58,7 @@
    diff --git a/reference/scale_coltab.html b/reference/scale_coltab.html index f9e903cd..a4ba6bbd 100644 --- a/reference/scale_coltab.html +++ b/reference/scale_coltab.html @@ -68,7 +68,7 @@
    diff --git a/reference/scale_cross_blended.html b/reference/scale_cross_blended.html index 25be940e..601856cd 100644 --- a/reference/scale_cross_blended.html +++ b/reference/scale_cross_blended.html @@ -104,7 +104,7 @@
    diff --git a/reference/scale_grass.html b/reference/scale_grass.html index 87d175c5..778c632f 100644 --- a/reference/scale_grass.html +++ b/reference/scale_grass.html @@ -88,7 +88,7 @@
    diff --git a/reference/scale_hypso.html b/reference/scale_hypso.html index 8d0fbd27..9b92fead 100644 --- a/reference/scale_hypso.html +++ b/reference/scale_hypso.html @@ -104,7 +104,7 @@
    diff --git a/reference/scale_princess.html b/reference/scale_princess.html index 0b423262..f51a93e3 100644 --- a/reference/scale_princess.html +++ b/reference/scale_princess.html @@ -84,7 +84,7 @@
    diff --git a/reference/scale_terrain.html b/reference/scale_terrain.html index 29375f3c..8ca1f522 100644 --- a/reference/scale_terrain.html +++ b/reference/scale_terrain.html @@ -76,7 +76,7 @@
    diff --git a/reference/scale_whitebox.html b/reference/scale_whitebox.html index b4d2a0f4..89273332 100644 --- a/reference/scale_whitebox.html +++ b/reference/scale_whitebox.html @@ -84,7 +84,7 @@
    diff --git a/reference/scale_wiki.html b/reference/scale_wiki.html index e862ed58..7c022c39 100644 --- a/reference/scale_wiki.html +++ b/reference/scale_wiki.html @@ -84,7 +84,7 @@
    diff --git a/reference/select.Spat.html b/reference/select.Spat.html index 084d315c..dc8d3a09 100644 --- a/reference/select.Spat.html +++ b/reference/select.Spat.html @@ -50,7 +50,7 @@
    diff --git a/reference/slice.Spat.html b/reference/slice.Spat.html index 34095dd0..8c4fd965 100644 --- a/reference/slice.Spat.html +++ b/reference/slice.Spat.html @@ -82,7 +82,7 @@
    diff --git a/reference/stat_spat_coordinates.html b/reference/stat_spat_coordinates.html index f6f0f5d1..452f84de 100644 --- a/reference/stat_spat_coordinates.html +++ b/reference/stat_spat_coordinates.html @@ -50,7 +50,7 @@
    diff --git a/reference/summarise.SpatVector.html b/reference/summarise.SpatVector.html index b20cd052..7ed09c13 100644 --- a/reference/summarise.SpatVector.html +++ b/reference/summarise.SpatVector.html @@ -60,7 +60,7 @@
    diff --git a/reference/tidyterra-package.html b/reference/tidyterra-package.html index 72d4bf03..385fb891 100644 --- a/reference/tidyterra-package.html +++ b/reference/tidyterra-package.html @@ -50,7 +50,7 @@
    diff --git a/reference/volcano2.html b/reference/volcano2.html index 4d63ed9a..02912adb 100644 --- a/reference/volcano2.html +++ b/reference/volcano2.html @@ -56,7 +56,7 @@
    diff --git a/search.json b/search.json index 80fe7a73..48659718 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"source","dir":"Articles","previous_headings":"Example data","what":"Source","title":"tidyterra FAQs","text":"article uses sample LiDAR Scotland Phase 5 - DSM provided Scottish Remote Sensing Portal. data made available Open Government Licence v3.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"about-the-file","dir":"Articles","previous_headings":"Example data","what":"About the file","title":"tidyterra FAQs","text":"file holyroodpark.tif represents DEM1 Holyrood Park, Edinburgh (Scotland), including Arthur’s Seat, extinct volcano, pretty much famous Maungawhau / Mount Eden volcano represented datasets::volcano. original file cropped -sampled demo purposes, holyroodpark.tif available online https://github.com/dieghernan/tidyterra/tree/main/data-raw folder.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"nas-remove","dir":"Articles","previous_headings":"","what":"NA values are shown in gray color","title":"tidyterra FAQs","text":"default behavior produced ggplot2 package. tidyterra color scales (.e., scale_fill_whitebox_c(), etc.), default parameter na.value set \"transparent\", prevents NA values filled2.","code":"library(terra) library(tidyterra) #> Error in get(paste0(generic, \".\", class), envir = get_method_env()) : #> object 'type_sum.accel' not found library(ggplot2) # Get a raster data from Holyrood Park, Edinburgh holyrood <- \"holyroodpark.tif\" r <- holyrood %>% rast() %>% filter(elevation > 80 & elevation < 180) # Default def <- ggplot() + geom_spatraster(data = r) def + labs( title = \"Default on ggplot2\", subtitle = \"NA values in grey\" ) # Modify with scales def + scale_fill_continuous(na.value = \"transparent\") + labs( title = \"Default colors on ggplot2\", subtitle = \"But NAs are not plotted\" ) # Use a different scale provided by ggplot2 def + scale_fill_viridis_c(na.value = \"orange\") + labs( title = \"Use any fill_* scale of ggplot2\", subtitle = \"Note that na.value = 'orange'\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"label-contour","dir":"Articles","previous_headings":"","what":"Labeling contours","title":"tidyterra FAQs","text":"Use geom_spatraster_contour_text() :","code":"library(terra) library(tidyterra) library(ggplot2) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) ggplot() + geom_spatraster_contour_text(data = r) + labs(title = \"Labelling contours\") # With options and aes # Use a labeller function so only selected breaks are labelled labeller <- function(labs) { # Must return a function function(x) { x[!x %in% labs] <- NA scales::label_comma(suffix = \" m.\")(x) } } # Common labels across ggplot labs <- c(100, 140, 180, 220) ggplot(r) + geom_spatraster_contour_text( data = r, aes( linewidth = after_stat(level), size = after_stat(level), color = after_stat(level) ), breaks = seq(100, 250, 10), # Just label some isolines label_format = labeller(labs = labs), family = \"mono\", fontface = \"bold\" ) + scale_linewidth_continuous(range = c(0.1, 0.5), breaks = labs) + scale_color_gradient(low = \"grey50\", high = \"grey10\", breaks = labs) + scale_size_continuous(range = c(2, 3), breaks = labs) + # Integrate scales guides( linewidth = guide_legend(\"meters\"), size = guide_legend(\"meters\"), color = guide_legend(\"meters\") ) + # Theme and titles theme_bw() + theme(text = element_text(family = \"mono\")) + labs( title = \"Labelling contours\", subtitle = \"With options: b/w plot\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"other-alternatives","dir":"Articles","previous_headings":"Labeling contours","what":"Other alternatives","title":"tidyterra FAQs","text":"Thanks fortify.SpatRaster() can use SpatRaster straight away metR package (see Hexagonal grids geoms). Use parameter(s) bins/binwidth/breaks align labels lines:","code":"library(metR) br <- seq(100, 250, 10) labs <- c(100, 140, 180, 220) # Replicate previous map with tidyterra + metR strategy ggplot(r, aes(x, y)) + geom_spatraster_contour( data = r, aes( linewidth = after_stat(level), color = after_stat(level) ), breaks = br, # Don't inherit fortified aes inherit.aes = FALSE ) + geom_text_contour( aes( z = elevation, color = after_stat(level), size = after_stat(level) ), breaks = br, # Text options check_overlap = TRUE, label.placer = label_placer_minmax(), stroke = 0.3, stroke.colour = \"white\", family = \"mono\", fontface = \"bold\", key_glyph = \"path\" ) + scale_linewidth_continuous(range = c(0.1, 0.5), breaks = labs) + scale_color_gradient(low = \"grey50\", high = \"grey10\", breaks = labs) + scale_size_continuous(range = c(2, 3), breaks = labs) + # Integrate scales guides( linewidth = guide_legend(\"meters\"), size = guide_legend(\"meters\"), color = guide_legend(\"meters\") ) + # Theme and titles theme_bw() + theme(text = element_text(family = \"mono\")) + labs( title = \"Labelling contours\", subtitle = \"tidyterra and metR: b/w plot\", x = \"\", y = \"\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"use-scale","dir":"Articles","previous_headings":"","what":"Using a different color scale","title":"tidyterra FAQs","text":"Since tidyterra leverages ggplot2, please refer ggplot2 use scales:","code":"library(terra) library(tidyterra) library(ggplot2) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) # Hillshade with grey colors slope <- terrain(r, \"slope\", unit = \"radians\") aspect <- terrain(r, \"aspect\", unit = \"radians\") hill <- shade(slope, aspect, 10, 340) ggplot() + geom_spatraster(data = hill, show.legend = FALSE) + # Note the scale, grey colours scale_fill_gradientn( colours = grey(0:100 / 100), na.value = \"transparent\" ) + labs(title = \"A hillshade plot with grey colors\")"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"can-i-change-the-default-palette-of-my-maps","dir":"Articles","previous_headings":"","what":"Can I change the default palette of my maps?","title":"tidyterra FAQs","text":"Yes, use options(\"ggplot2.continuous.fill\") modify default colors session.","code":"library(terra) library(tidyterra) library(ggplot2) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) p <- ggplot() + geom_spatraster(data = r) # Set options tmp <- getOption(\"ggplot2.continuous.fill\") # store current setting options(ggplot2.continuous.fill = scale_fill_grass_c) p # restore previous setting options(ggplot2.continuous.fill = tmp) p"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"blurry-tiles","dir":"Articles","previous_headings":"","what":"My map tiles are blurry","title":"tidyterra FAQs","text":"probably related tile rather package. base tiles provided EPSG:3857, check first tile CRS different one. EPSG:3857 may indication tile reprojected, implied sort sampling causes blurriness data. Also, modify parameter maxcell avoid resampling force ggplot2 map EPSG:3857 ggplot2::coord_sf(crs = 3857):","code":"library(terra) library(tidyterra) library(ggplot2) library(sf) library(maptiles) # Get a tile from a point on sf format p <- st_point(c(-3.166011, 55.945235)) %>% st_sfc(crs = 4326) %>% st_buffer(500) tile1 <- get_tiles(p, provider = \"OpenStreetMap\", zoom = 14, cachedir = \".\", crop = TRUE ) ggplot() + geom_spatraster_rgb(data = tile1) + labs(title = \"This is a bit blurry...\") + theme_void() st_crs(tile1)$epsg #> [1] 4326 # The tile was in EPSG 4326 # get tile in 3857 p2 <- st_transform(p, 3857) tile2 <- get_tiles(p2, provider = \"OpenStreetMap\", zoom = 14, cachedir = \".\", crop = TRUE ) st_crs(tile2)$epsg #> [1] 3857 # Now the tile is EPSG:3857 ggplot() + geom_spatraster_rgb(data = tile2, maxcell = Inf) + # Force crs to be 3857 coord_sf(crs = 3857) + labs(title = \"...compared with this one\") + theme_void()"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"axis-degrees","dir":"Articles","previous_headings":"","what":"Avoid degrees labeling on axis","title":"tidyterra FAQs","text":", ggplot2 default, can modified ggplot2::coord_sf(datum) argument:","code":"library(terra) library(tidyterra) library(ggplot2) library(sf) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) ggplot() + geom_spatraster(data = r) + labs( title = \"Axis auto-converted to lon/lat\", subtitle = paste(\"But SpatRaster is EPSG:\", st_crs(r)$epsg) ) # Use datum ggplot() + geom_spatraster(data = r) + coord_sf(datum = pull_crs(r)) + labs( title = \"Axis on the units of the SpatRaster\", subtitle = paste(\"EPSG:\", st_crs(r)$epsg) )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"axis-breaks","dir":"Articles","previous_headings":"","what":"Modifying the number of breaks on axis","title":"tidyterra FAQs","text":"best option pass custom breaks ggplot2::scale_x_continous() ggplot2::scale_y_continous(). need provide breaks lon/lat even data projected. See also ggplot2/issues/4622:","code":"library(terra) library(tidyterra) library(ggplot2) library(sf) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) ggplot() + geom_spatraster(data = r) + labs(title = \"Default axis breaks\") # Modify y breaks with extent projected in EPSG:4326 # Get extent ext <- r %>% project(\"EPSG:4326\", mask = TRUE) %>% ext() %>% as.vector() ggplot() + geom_spatraster(data = r) + scale_x_continuous( expand = expansion(mult = 0.05), breaks = scales::breaks_pretty(n = 3)(ext[c(\"xmin\", \"xmax\")]) ) + labs(title = \"Three breaks on x (¿?)\")"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"plotting-a-spatraster-with-color-tables","dir":"Articles","previous_headings":"","what":"Plotting a SpatRaster with color tables","title":"tidyterra FAQs","text":"tidyterra several ways handle SpatRaster objects. use file clc_edinburgh.tif, available online https://github.com/dieghernan/tidyterra/tree/main/data-raw folder, representing information Corine Land Cover Dataset (2018) city Edinburgh3.","code":"library(terra) library(tidyterra) library(ggplot2) # Get a SpatRaster with coltab r_coltab <- rast(\"clc_edinburgh.tif\") has.colors(r_coltab) #> [1] TRUE r_coltab #> class : SpatRaster #> dimensions : 196, 311, 1 (nrow, ncol, nlyr) #> resolution : 178.8719, 177.9949 (x, y) #> extent : -380397.3, -324768.1, 7533021, 7567908 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source : clc_edinburgh.tif #> color table : 1 #> categories : label #> name : label #> min value : Continuous urban fabric #> max value : Sea and ocean # Native handling by terra packages plot(r_coltab) # A. autoplot autoplot(r_coltab, maxcell = Inf) + guides(fill = guide_legend(ncol = 1)) + ggtitle(\"autoplot method\") # B. geom_spatraster ggplot() + geom_spatraster(data = r_coltab, maxcell = Inf) + guides(fill = guide_legend(ncol = 1)) + ggtitle(\"geom_spatraster method\") # C. Using scale_fill_coltab g <- ggplot() + geom_spatraster(data = r_coltab, use_coltab = FALSE, maxcell = Inf) + guides(fill = guide_legend(ncol = 1)) g # But... g + scale_fill_coltab(data = r_coltab) + ggtitle(\"scale_fill_coltab method\") # D. Extract named colors and scale_fill_manual cols <- get_coltab_pal(r_coltab) cols #> Continuous urban fabric #> \"#E6004D\" #> Discontinuous urban fabric #> \"#FF0000\" #> Industrial or commercial units #> \"#CC4DF2\" #> Road and rail networks and associated land #> \"#CC0000\" #> Port areas #> \"#E6CCCC\" #> Airports #> \"#E6CCE6\" #> Mineral extraction sites #> \"#A600CC\" #> Dump sites #> \"#A64D00\" #> Construction sites #> \"#FF4DFF\" #> Green urban areas #> \"#FFA6FF\" #> Sport and leisure facilities #> \"#FFE6FF\" #> Non-irrigated arable land #> \"#FFFFA8\" #> Pastures #> \"#E6E64D\" #> Broad-leaved forest #> \"#80FF00\" #> Coniferous forest #> \"#00A600\" #> Mixed forest #> \"#4DFF00\" #> Natural grasslands #> \"#CCF24D\" #> Moors and heathland #> \"#A6FF80\" #> Bare rocks #> \"#CCCCCC\" #> Intertidal flats #> \"#A6A6E6\" #> Water bodies #> \"#80F2E6\" #> Estuaries #> \"#A6FFE6\" #> Sea and ocean #> \"#E6F2FF\" scales::show_col(cols) # And now g + scale_fill_manual( values = cols, na.value = \"transparent\", na.translate = FALSE ) + ggtitle(\"scale_fill_manual method\")"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"gganimate","dir":"Articles","previous_headings":"","what":"Use with gganimate","title":"tidyterra FAQs","text":"Sure! See example (thanks @frzambra):","code":"library(gganimate) library(tidyterra) library(geodata) library(ggplot2) temp <- worldclim_country(\"che\", \"tavg\", path = \".\") che_cont <- gadm(\"che\", level = 0, path = \".\") temp_m <- crop(temp, che_cont, mask = TRUE) names(temp_m) <- month.name anim <- ggplot() + geom_spatraster(data = temp_m) + scale_fill_viridis_c( option = \"inferno\", na.value = \"transparent\", labels = scales::label_number(suffix = \"º C\") ) + transition_manual(lyr) + theme_bw() + theme( axis.text = element_blank(), axis.ticks = element_blank() ) + labs( title = \"Avg temp Switzerland: {current_frame}\", fill = \"\" ) gganimate::animate(anim, duration = 12, device = \"ragg_png\")"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"north-arrows-and-scale-bar","dir":"Articles","previous_headings":"","what":"North arrows and scale bar","title":"tidyterra FAQs","text":"tidyterra provide graphical objects ggplot2 plots. However, can use ggspatial functions (ggspatial::annotation_north_arrow() ggspatial::annotation_scale()):","code":"library(terra) library(tidyterra) library(ggplot2) library(ggspatial) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) autoplot(r) + annotation_north_arrow( which_north = TRUE, pad_x = unit(0.8, \"npc\"), pad_y = unit(0.75, \"npc\"), style = north_arrow_fancy_orienteering() ) + annotation_scale( height = unit(0.015, \"npc\"), width_hint = 0.5, pad_x = unit(0.07, \"npc\"), pad_y = unit(0.07, \"npc\"), text_cex = .8 )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"how-to-overlay-a-spatraster-over-a-rgb-tile","dir":"Articles","previous_headings":"","what":"How to overlay a SpatRaster over a RGB tile","title":"tidyterra FAQs","text":"quite straightforward, just use geom_spatraster_rgb() command just create layer: can create another variations binned legends filled contours (see geom_spatraster_contour_filled()):","code":"library(terra) library(tidyterra) library(ggplot2) library(sf) # Get example data library(maptiles) library(geodata) # Area of interest aoi <- gadm(country = \"CHE\", path = \".\", level = 0) %>% project(\"EPSG:3857\") # Tile rgb_tile <- get_tiles(aoi, crop = TRUE, provider = \"Esri.WorldShadedRelief\", zoom = 8, project = FALSE, cachedir = \".\" ) # Clim (mean prec) clim <- worldclim_country(\"CHE\", var = \"prec\", path = \".\") %>% project(rgb_tile) %>% mask(aoi) %>% terra::mean() # Labels cap_lab <- paste0( c( \"Tiles © Esri - Source: Esri\", \"Data: © Copyright 2020-2022, worldclim.org.\" ), collapse = \"\\n\" ) tit_lab <- \"Average precipitation in Switzerland\" ggplot(aoi) + geom_spatraster_rgb(data = rgb_tile, alpha = 1) + geom_spatraster(data = clim) + geom_spatvector(fill = NA) + scale_fill_whitebox_c( palette = \"deep\", alpha = 0.5, labels = scales::label_number(suffix = \" mm.\") ) + coord_sf(expand = FALSE) + labs( title = tit_lab, subtitle = \"With continuous overlay\", fill = \"Precipitation\", caption = cap_lab ) # Binned ggplot(aoi) + geom_spatraster_rgb(data = rgb_tile, alpha = 1) + geom_spatraster(data = clim) + geom_spatvector(fill = NA) + scale_fill_whitebox_b( palette = \"deep\", alpha = 0.5, n.breaks = 4, labels = scales::label_number(suffix = \" mm.\") ) + coord_sf(expand = FALSE) + labs( title = tit_lab, subtitle = \"With overlay: binned legend\", fill = \"Precipitation\", caption = cap_lab ) # Filled contour ggplot(aoi) + geom_spatraster_rgb(data = rgb_tile, alpha = 1) + geom_spatraster_contour_filled(data = clim, bins = 4) + geom_spatvector(fill = NA) + coord_sf(expand = FALSE) + scale_fill_whitebox_d( palette = \"deep\", alpha = 0.5, guide = guide_legend(reverse = TRUE) ) + labs( title = tit_lab, subtitle = \"With overlay and filled contour\", fill = \"Precipitation (mm.)\", caption = cap_lab )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"fort","dir":"Articles","previous_headings":"","what":"Hexagonal grids (and other geoms)","title":"tidyterra FAQs","text":"concept cells SpatRaster rectangular, possible create SpatRaster .e. hexagonal cells. possible create plot hexagonal cells thanks fortify.SpatRaster() stat_summary_hex(). Additional work needed adjust final plot, specifically needed also use coord_sf(): Note need make direct call fortify.SpatRaster(), since function implicitly invoked ggplot2 using ggplot(data = a_spatraster). Thanks extension mechanism, possible use additional geoms stats provided ggplot2:","code":"library(terra) library(tidyterra) library(ggplot2) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) # With hex grid ggplot(r, aes(x, y, z = elevation)) + stat_summary_hex( fun = mean, color = NA, linewidth = 0, # Bins size determines the number of cells displayed bins = 30 ) + coord_sf(crs = pull_crs(r)) + labs( title = \"Hexagonal SpatRaster\", subtitle = \"Using fortify (implicit) and stat_summary_hex\", x = NULL, y = NULL ) # Point plot ggplot(r, aes(x, y, z = elevation), maxcell = 1000) + geom_point(aes(size = elevation, alpha = elevation), fill = \"darkblue\", color = \"grey50\", shape = 21 ) + coord_sf(crs = pull_crs(r)) + scale_radius(range = c(1, 5)) + scale_alpha(range = c(0.01, 1)) + labs( title = \"SpatRaster as points\", subtitle = \"Using fortify (implicit)\", x = NULL, y = NULL )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"tidyterra-and-metr","dir":"Articles","previous_headings":"Hexagonal grids (and other geoms)","what":"tidyterra and metR","title":"tidyterra FAQs","text":"metR package also provides ggplot2 extensions, mainly focused analysis meteorological fields. shown previously (see Labeling contours) possible use packages provide rich plots. section shows demos.","code":"# load libraries and files library(terra) library(tidyterra) library(ggplot2) library(metR) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood)"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"metrgeom_contour_tanaka","dir":"Articles","previous_headings":"Hexagonal grids (and other geoms) > tidyterra and metR","what":"metR::geom_contour_tanaka()","title":"tidyterra FAQs","text":"","code":"ggplot(r, aes(x, y)) + geom_spatraster(data = r, inherit.aes = FALSE) + geom_contour_tanaka(aes(z = elevation), breaks = seq(0, 250, 25)) + scale_fill_viridis_c(option = \"magma\") + labs(x = \"\", y = \"\", title = \"tidyterra and metR: tanaka contours\") # Using geom_spatraster_contour_filled ggplot(r, aes(x, y)) + geom_spatraster_contour_filled( data = r, inherit.aes = FALSE, breaks = seq(0, 250, 50) ) + geom_contour_tanaka(aes(z = elevation), breaks = seq(0, 250, 10), sun.angle = -90, dark = \"gray50\" ) + scale_fill_viridis_d(option = \"cividis\") + labs( x = \"\", y = \"\", title = \"tidyterra and metR: tanaka contours\", subtitle = \"with geom_contour_filled\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"metrgeom_relief","dir":"Articles","previous_headings":"Hexagonal grids (and other geoms) > tidyterra and metR","what":"metR::geom_relief()","title":"tidyterra FAQs","text":"","code":"ggplot(r, aes(x, y)) + geom_relief(aes(z = elevation)) + geom_spatraster( data = r, inherit.aes = FALSE, aes(alpha = after_stat(value)) ) + scale_fill_cross_blended_c(breaks = seq(0, 250, 25)) + scale_alpha(range = c(1, 0.25)) + guides(alpha = \"none\", fill = guide_legend(reverse = TRUE)) + labs(x = \"\", y = \"\", title = \"tidyterra and metR: reliefs\")"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"session-info","dir":"Articles","previous_headings":"","what":"Session info","title":"tidyterra FAQs","text":"","code":"#> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.4.2 (2024-10-31 ucrt) #> os Windows Server 2022 x64 (build 20348) #> system x86_64, mingw32 #> ui RTerm #> language en #> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz UTC #> date 2025-01-07 #> pandoc 3.1.11 @ C:/HOSTED~1/windows/pandoc/31F387~1.11/x64/PANDOC~1.11/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> backports 1.5.0 2024-05-23 [1] RSPM #> bslib 0.8.0 2024-07-29 [1] RSPM #> cachem 1.1.0 2024-05-16 [1] RSPM #> checkmate 2.3.2 2024-07-29 [1] RSPM #> class 7.3-22 2023-05-03 [3] CRAN (R 4.4.2) #> classInt 0.4-10 2023-09-05 [1] RSPM #> cli 3.6.3 2024-06-21 [1] RSPM #> codetools 0.2-20 2024-03-31 [3] CRAN (R 4.4.2) #> colorspace 2.1-1 2024-07-26 [1] RSPM #> data.table 1.16.4 2024-12-06 [1] RSPM #> DBI 1.2.3 2024-06-02 [1] RSPM #> desc 1.4.3 2023-12-10 [1] RSPM #> digest 0.6.37 2024-08-19 [1] RSPM #> dplyr 1.1.4 2023-11-17 [1] RSPM #> e1071 1.7-16 2024-09-16 [1] RSPM #> evaluate 1.0.1 2024-10-10 [1] RSPM #> farver 2.1.2 2024-05-13 [1] RSPM #> fastmap 1.2.0 2024-05-15 [1] RSPM #> fs 1.6.5 2024-10-30 [1] RSPM #> generics 0.1.3 2022-07-05 [1] RSPM #> geodata * 0.6-2 2024-06-10 [1] RSPM #> ggplot2 * 3.5.1 2024-04-23 [1] RSPM #> ggspatial * 1.1.9 2023-08-17 [1] RSPM #> glue 1.8.0 2024-09-30 [1] RSPM #> gtable 0.3.6 2024-10-25 [1] RSPM #> hexbin 1.28.5 2024-11-13 [1] RSPM #> htmltools 0.5.8.1 2024-04-04 [1] RSPM #> isoband 0.2.7 2022-12-20 [1] RSPM #> jquerylib 0.1.4 2021-04-26 [1] RSPM #> jsonlite 1.8.9 2024-09-20 [1] RSPM #> KernSmooth 2.23-24 2024-05-17 [3] CRAN (R 4.4.2) #> knitr 1.49 2024-11-08 [1] RSPM #> labeling 0.4.3 2023-08-29 [1] RSPM #> lattice 0.22-6 2024-03-20 [3] CRAN (R 4.4.2) #> lifecycle 1.0.4 2023-11-07 [1] RSPM #> magrittr 2.0.3 2022-03-30 [1] RSPM #> maptiles * 0.8.0 2024-10-22 [1] RSPM #> memoise 2.0.1 2021-11-26 [1] RSPM #> metR * 0.16.0 2024-10-14 [1] RSPM #> munsell 0.5.1 2024-04-01 [1] RSPM #> pillar 1.10.0 2024-12-17 [1] RSPM #> pkgconfig 2.0.3 2019-09-22 [1] RSPM #> pkgdown 2.1.1 2024-09-17 [1] RSPM #> plyr 1.8.9 2023-10-02 [1] RSPM #> proxy 0.4-27 2022-06-09 [1] RSPM #> purrr 1.0.2 2023-08-10 [1] RSPM #> R.cache 0.16.0 2022-07-21 [1] RSPM #> R.methodsS3 1.8.2 2022-06-13 [1] RSPM #> R.oo 1.27.0 2024-11-01 [1] RSPM #> R.utils 2.12.3 2023-11-18 [1] RSPM #> R6 2.5.1 2021-08-19 [1] RSPM #> ragg 1.3.3 2024-09-11 [1] RSPM #> Rcpp 1.0.13-1 2024-11-02 [1] RSPM #> rlang 1.1.4 2024-06-04 [1] RSPM #> rmarkdown 2.29 2024-11-04 [1] RSPM #> s2 1.1.7 2024-07-17 [1] RSPM #> sass 0.4.9 2024-03-15 [1] RSPM #> scales 1.3.0 2023-11-28 [1] RSPM #> sessioninfo * 1.2.2 2021-12-06 [1] any (@1.2.2) #> sf * 1.0-19 2024-11-05 [1] RSPM #> styler 1.10.3 2024-04-07 [1] RSPM #> systemfonts 1.1.0 2024-05-15 [1] RSPM #> terra * 1.8-5 2024-12-12 [1] RSPM #> textshaping 0.4.1 2024-12-06 [1] RSPM #> tibble 3.2.1 2023-03-20 [1] RSPM #> tidyr 1.3.1 2024-01-24 [1] RSPM #> tidyselect 1.2.1 2024-03-11 [1] RSPM #> tidyterra * 0.6.2 2025-01-07 [1] local #> units 0.8-5 2023-11-28 [1] RSPM #> vctrs 0.6.5 2023-12-01 [1] RSPM #> viridisLite 0.4.2 2023-05-02 [1] RSPM #> withr 3.0.2 2024-10-28 [1] RSPM #> wk 0.9.4 2024-10-11 [1] RSPM #> xfun 0.49 2024-10-31 [1] RSPM #> yaml 2.3.10 2024-07-26 [1] RSPM #> #> [1] D:/a/_temp/Library #> [2] C:/R/site-library #> [3] C:/R/library #> #> ──────────────────────────────────────────────────────────────────────────────"},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_terrain_-and-scale_fill_wiki_","dir":"Articles","previous_headings":"","what":"scale_fill_terrain_* and scale_fill_wiki_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_terrain_c() scale_fill_wiki_c() info.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_whitebox_","dir":"Articles","previous_headings":"","what":"scale_fill_whitebox_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_whitebox_c() info.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_hypso_","dir":"Articles","previous_headings":"","what":"scale_fill_hypso_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_hypso_c() info.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_cross_blended_","dir":"Articles","previous_headings":"","what":"scale_fill_cross_blended_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_cross_blended_c() info.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_grass_","dir":"Articles","previous_headings":"","what":"scale_fill_grass_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_grass_c() info. Plots produced using use_grass_range = FALSE.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_princess_","dir":"Articles","previous_headings":"","what":"scale_fill_princess_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_princess_c() info.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"session-info","dir":"Articles","previous_headings":"","what":"Session info","title":"Gradient palettes in tidyterra","text":"","code":"#> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.4.2 (2024-10-31 ucrt) #> os Windows Server 2022 x64 (build 20348) #> system x86_64, mingw32 #> ui RTerm #> language en #> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz UTC #> date 2025-01-07 #> pandoc 3.1.11 @ C:/HOSTED~1/windows/pandoc/31F387~1.11/x64/PANDOC~1.11/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> bslib 0.8.0 2024-07-29 [1] RSPM #> cachem 1.1.0 2024-05-16 [1] RSPM #> class 7.3-22 2023-05-03 [3] CRAN (R 4.4.2) #> classInt 0.4-10 2023-09-05 [1] RSPM #> cli 3.6.3 2024-06-21 [1] RSPM #> codetools 0.2-20 2024-03-31 [3] CRAN (R 4.4.2) #> colorspace 2.1-1 2024-07-26 [1] RSPM #> data.table 1.16.4 2024-12-06 [1] RSPM #> DBI 1.2.3 2024-06-02 [1] RSPM #> desc 1.4.3 2023-12-10 [1] RSPM #> digest 0.6.37 2024-08-19 [1] RSPM #> dplyr 1.1.4 2023-11-17 [1] RSPM #> e1071 1.7-16 2024-09-16 [1] RSPM #> evaluate 1.0.1 2024-10-10 [1] RSPM #> farver 2.1.2 2024-05-13 [1] RSPM #> fastmap 1.2.0 2024-05-15 [1] RSPM #> fs 1.6.5 2024-10-30 [1] RSPM #> generics 0.1.3 2022-07-05 [1] RSPM #> ggplot2 * 3.5.1 2024-04-23 [1] RSPM #> glue 1.8.0 2024-09-30 [1] RSPM #> gtable 0.3.6 2024-10-25 [1] RSPM #> htmltools 0.5.8.1 2024-04-04 [1] RSPM #> jquerylib 0.1.4 2021-04-26 [1] RSPM #> jsonlite 1.8.9 2024-09-20 [1] RSPM #> KernSmooth 2.23-24 2024-05-17 [3] CRAN (R 4.4.2) #> knitr 1.49 2024-11-08 [1] RSPM #> labeling 0.4.3 2023-08-29 [1] RSPM #> lifecycle 1.0.4 2023-11-07 [1] RSPM #> magrittr 2.0.3 2022-03-30 [1] RSPM #> munsell 0.5.1 2024-04-01 [1] RSPM #> pillar 1.10.0 2024-12-17 [1] RSPM #> pkgconfig 2.0.3 2019-09-22 [1] RSPM #> pkgdown 2.1.1 2024-09-17 [1] RSPM #> proxy 0.4-27 2022-06-09 [1] RSPM #> purrr 1.0.2 2023-08-10 [1] RSPM #> R.cache 0.16.0 2022-07-21 [1] RSPM #> R.methodsS3 1.8.2 2022-06-13 [1] RSPM #> R.oo 1.27.0 2024-11-01 [1] RSPM #> R.utils 2.12.3 2023-11-18 [1] RSPM #> R6 2.5.1 2021-08-19 [1] RSPM #> ragg 1.3.3 2024-09-11 [1] RSPM #> Rcpp 1.0.13-1 2024-11-02 [1] RSPM #> rlang 1.1.4 2024-06-04 [1] RSPM #> rmarkdown 2.29 2024-11-04 [1] RSPM #> sass 0.4.9 2024-03-15 [1] RSPM #> scales 1.3.0 2023-11-28 [1] RSPM #> sessioninfo * 1.2.2 2021-12-06 [1] any (@1.2.2) #> sf 1.0-19 2024-11-05 [1] RSPM #> styler 1.10.3 2024-04-07 [1] RSPM #> systemfonts 1.1.0 2024-05-15 [1] RSPM #> terra 1.8-5 2024-12-12 [1] RSPM #> textshaping 0.4.1 2024-12-06 [1] RSPM #> tibble 3.2.1 2023-03-20 [1] RSPM #> tidyr 1.3.1 2024-01-24 [1] RSPM #> tidyselect 1.2.1 2024-03-11 [1] RSPM #> tidyterra * 0.6.2 2025-01-07 [1] local #> units 0.8-5 2023-11-28 [1] RSPM #> vctrs 0.6.5 2023-12-01 [1] RSPM #> withr 3.0.2 2024-10-28 [1] RSPM #> xfun 0.49 2024-10-31 [1] RSPM #> yaml 2.3.10 2024-07-26 [1] RSPM #> #> [1] D:/a/_temp/Library #> [2] C:/R/site-library #> [3] C:/R/library #> #> ──────────────────────────────────────────────────────────────────────────────"},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Using the tidyverse with terra objects: the tidyterra package","text":"tidyterra R (R Core Team 2023) package allows manipulation spatial data objects provided terra package (Hijmans 2023), using verbs packages included tidyverse (Wickham et al. 2019), dplyr (Wickham et al. 2023), tidyr (Wickham, Vaughan, Girlich 2023), tibble (Müller Wickham 2023). addition enables users already familiar tidyverse approach spatial data manipulation analysis easily much faster. Furthermore, tidyterra extends functionality ggplot2 package (Wickham 2016) providing additional geoms stats 1 like geom_spatraster() geom_spatvector(), well carefully chosen scales color palettes specifically designed map production. tidyterra can manipulate following classes terra objects: SpatVector objects, represent vector data points, lines, polygon geometries. SpatRaster objects, represent raster data form grid consisting equally sized rectangles. rectangle can contain one values. first stable version tidyterra included CRAN April 24, 2022, actively used packages (ebvcuve (Quoss et al. 2021), biomod2 (Thuiller et al. 2023), inlabru (Bachl et al. 2019), RCzechia (Lacko 2023) sparrpowR (Buller et al. 2021)) cited academic research publications (Bahlburg et al. (2023), Moraga (2024), Leonardi, Colucci, Manica (2023), Meister et al. (2023)) ever since.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"statement-of-need","dir":"Articles","previous_headings":"","what":"Statement of need","title":"Using the tidyverse with terra objects: the tidyterra package","text":"tidyverse compilation R packages share underlying design philosophy, grammar, data structures. packages within tidyverse widely used R users tidying, transforming, visualizing data. tidyverse designed work tidy data (“every column variable, every row observation, every cell single value”), represented form data frames tibbles. However, possible extend functionality tidyverse packages work new R object classes registering corresponding S3 methods (Wickham 2019). means dplyr::mutate() can adapted work object class foo creating corresponding S3 method mutate.foo(). popular packages designed spatial data handling, sf (Pebesma 2018) stars (Pebesma Bivand 2023), already provide integration tidyverse part infrastructure, terra objects lack integration natively. Although terra offers wide set functions transforming visualizing SpatRaster SpatVector objects, users familiar package need make additional effort learn syntax. may imply additional challenge initial steps field spatial analysis. tidyterra package developed address integration gap. providing corresponding S3 methods, data analysts can apply syntax functions already familiar rectangular data objects provided terra. enables users familiar spatial data analysis approach area easily. addition, tidyterra also offers functions plotting terra objects using ggplot2 syntax. Although packages like rasterVis (Perpiñán Hijmans 2023) ggspatial (Dunnington 2023) already allow representation SpatRaster objects via ggplot2, tidyterra functions provide additional support advanced mapping. support includes integration faceted maps, contours, automatic conversion spatial layers CRS2 via ggplot2::coord_sf(). Furthermore, tidyterra also provides support SpatVector objects, similar native support sf objects ggplot2 package. Lastly, tidyterra provides collection color palettes specifically designed representing spatial phenomena (Lindsay 2018). Additionally, implements cross-blended hypsometric tints described Patterson Jenny (2011).","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"a-note-on-performance","dir":"Articles","previous_headings":"","what":"A note on performance","title":"Using the tidyverse with terra objects: the tidyterra package","text":"development philosophy tidyterra consists adapting terra objects data frame-like structures performing different data transformations, ultimately may impact performance package. manipulating large raster files (.e. 10.000.000 cells), recommended use native terra syntax, specifically designed handling type files. case plotting, default behavior geoms provided resample SpatRaster presents 500.000 cells speed process (terra::plot() ), however upper limit can modified using maxcell parameter geom function. Note also possible, help page function tidyterra references equivalent terra.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"example-of-use","dir":"Articles","previous_headings":"","what":"Example of use","title":"Using the tidyverse with terra objects: the tidyterra package","text":"tidyterra available CRAN, can easily installed using following commands R: latest developing version hosted GitHub can installed using following command R: following example demonstrates manipulate SpatRaster object using dplyr syntax. Additionally, illustrates seamlessly plot SpatRaster object ggplot2 using geom_spatraster() function: Faceted map multi-layer raster file. following example combine common dplyr workflow (mutate() + select()) plot result. case plot contour plot original SpatRaster using geom_spatraster_contour_filled()also includes overlay SpatVector reference: Contour map temperature variation SpatVector overlay","code":"install.packages(\"tidyterra\") remotes::install_github(\"dieghernan/tidyterra\") library(tidyterra) library(tidyverse) # Load all the packages of tidyverse at once library(scales) # Additional library for labels # Temperatures in Castille and Leon (selected months) rastertemp <- terra::rast(system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\" )) # Rename with the tidyverse rastertemp <- rastertemp %>% rename(April = tavg_04, May = tavg_05, June = tavg_06) # Plot with facets ggplot() + geom_spatraster(data = rastertemp) + facet_wrap(~lyr, ncol = 2) + scale_fill_whitebox_c( palette = \"muted\", labels = label_number(suffix = \"º\"), n.breaks = 12, guide = guide_legend(reverse = TRUE) ) + labs( fill = \"\", title = \"Average temperature in Castille and Leon (Spain)\", subtitle = \"Months of April, May and June\" ) # Compute the variation between April and June and apply a different palette incr_temp <- rastertemp %>% mutate(var = June - April) %>% select(Variation = var) # Overlay an SpatVector cyl_vect <- terra::vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\" )) # Contour map with overlay ggplot() + geom_spatraster_contour_filled(data = incr_temp) + geom_spatvector(data = cyl_vect, fill = NA) + scale_fill_whitebox_d(palette = \"bl_yl_rd\") + theme_grey() + labs( fill = \"º Celsius\", title = \"Variation of temperature in Castille and Leon (Spain)\", subtitle = \"Difference between April and June\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"additional-materials","dir":"Articles","previous_headings":"","what":"Additional materials","title":"Using the tidyverse with terra objects: the tidyterra package","text":"package includes extensive documentation available online https://dieghernan.github.io/tidyterra/ including: Details function, including (possible) equivalent terra function, case users prefer include workflows. Working examples use functions creation plots. Additional articles vignettes, well complete demo different color palettes included package (see Palettes).","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"acknowledgements","dir":"Articles","previous_headings":"","what":"Acknowledgements","title":"Using the tidyverse with terra objects: the tidyterra package","text":"like thank Robert J. Hijmans advice support adapting methods, well suggestions helped us improve functionalities package. also thankful Dewey Dunnington, Brent Thorne rest contributors ggspatial package, served key reference initial stages development tidyterra. tidyterra also incorporates pieces code adapted ggplot2 computing contours, relies package isoband (Wickham, Wilke, Pedersen 2022) developed Claus O. Wilke.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"welcome-to-tidyterra","dir":"Articles","previous_headings":"","what":"Welcome to {tidyterra}","title":"Welcome to tidyterra","text":"tidyterra package adds common methods tidyverse SpatRaster SpatVectors objects created terra package. also adds specific geom_spat*() functions plotting kind objects ggplot2.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"why-tidyterra","dir":"Articles","previous_headings":"Welcome to {tidyterra}","what":"Why tidyterra?","title":"Welcome to tidyterra","text":"Spat* objects like regular data frames. different type objects, implemented via S4 object system, syntax computation methods, implemented terra package. implementing tidyverse methods objects, specifically dplyr tidyr methods, useR can now work easily Spat* objects, just like (s)tabular data. Note terms performance, terra much optimized working kind objects, recommended also learn bit terra syntax. function tidyterra refers (possible) corresponding equivalent terra.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"a-note-for-advanced-terra-users","dir":"Articles","previous_headings":"","what":"A note for advanced terra users","title":"Welcome to tidyterra","text":"previously mentioned, tidyterra optimized terms performance. Specially working filter() mutate() methods, can slow. rule thumb, tidyterra can handle objects less 10.000.000 slots information (.e., terra::ncell(a_rast) * terra::nlyr(a_rast) < 10e6).","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"get-started-with-tidyterra","dir":"Articles","previous_headings":"","what":"Get started with tidyterra","title":"Welcome to tidyterra","text":"Load tidyterra additional libraries tidyverse: Currently, following methods available: Let’s see action:","code":"library(tidyterra) library(dplyr) library(tidyr)"},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"spatrasters","dir":"Articles","previous_headings":"Get started with tidyterra","what":"SpatRasters","title":"Welcome to tidyterra","text":"See example SpatRaster objects: previous example, : Eliminated first layer raster tavg_04. Created new layer newcol difference layers tavg_05 tavg_06. Relocated newcol first layer SpatRaster. Replaced NA cells newcol 3. Renamed newcol difference. process, essential properties SpatRaster (number cells, columns rows, extent, resolution coordinate reference system) modified. methods filter(), slice() drop_na() can modify properties, applied data frame (number rows modified case).","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") temp <- rast(f) temp #> class : SpatRaster #> dimensions : 87, 118, 3 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source : cyl_temp.tif #> names : tavg_04, tavg_05, tavg_06 #> min values : 1.885463, 5.817587, 10.46338 #> max values : 13.283829, 16.740898, 21.11378 mod <- temp %>% select(-1) %>% mutate(newcol = tavg_06 - tavg_05) %>% relocate(newcol, .before = 1) %>% replace_na(list(newcol = 3)) %>% rename(difference = newcol) mod #> class : SpatRaster #> dimensions : 87, 118, 3 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source(s) : memory #> names : difference, tavg_05, tavg_06 #> min values : 2.817647, 5.817587, 10.46338 #> max values : 5.307511, 16.740898, 21.11378"},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"spatvectors","dir":"Articles","previous_headings":"Get started with tidyterra","what":"SpatVectors","title":"Welcome to tidyterra","text":"tidyterra >= 0.4.0 provides support SpatVectors dplyr tidyr methods, possible arrange, group summarise information SpatVectors. case SpatRaster, basic properties geometry CRS preserved.","code":"lux <- system.file(\"ex/lux.shp\", package = \"terra\") v_lux <- vect(lux) v_lux %>% # Create categories mutate(gr = cut(POP / 1000, 5)) %>% group_by(gr) %>% # Summary summarise( n = n(), tot_pop = sum(POP), mean_area = mean(AREA) ) %>% # Arrange arrange(desc(gr)) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 4 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : gr n tot_pop mean_area #> type : #> values : (147,183] 2 3.594e+05 244 #> (40.7,76.1] 1 4.819e+04 185 #> (4.99,40.7] 9 1.944e+05 209.8"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"spatrasters-1","dir":"Articles","previous_headings":"Plotting with ggplot2","what":"SpatRasters","title":"Welcome to tidyterra","text":"tidyterra provides several geom_* SpatRasters. SpatRaster CRS informed (.e. terra::crs(a_rast) != \"\"), geom uses ggplot2::coord_sf(), may also reprojected adjusting coordinates spatial layers: faceted SpatRaster Contour lines plot SpatRaster Contour filled plot SpatRaster tidyterra can also plot RGB SpatRasters add imagery plots: Plotting RGB SpatRaster tidyterra provides selected scales suitable creating hypsometric bathymetric maps: Hypsometric tints","code":"library(ggplot2) # A faceted SpatRaster ggplot() + geom_spatraster(data = temp) + facet_wrap(~lyr) + scale_fill_whitebox_c( palette = \"muted\", na.value = \"white\" ) # Contour lines for a specific layer f_volcano <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") volcano2 <- rast(f_volcano) ggplot() + geom_spatraster(data = volcano2) + geom_spatraster_contour(data = volcano2, breaks = seq(80, 200, 5)) + scale_fill_whitebox_c() + coord_sf(expand = FALSE) + labs(fill = \"elevation\") # Contour filled ggplot() + geom_spatraster_contour_filled(data = volcano2) + scale_fill_whitebox_d(palette = \"atlas\") + labs(fill = \"elevation\") # Read a vector f_v <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- vect(f_v) # Read a tile f_rgb <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") r_rgb <- rast(f_rgb) rgb_plot <- ggplot(v) + geom_spatraster_rgb(data = r_rgb) + geom_spatvector(fill = NA, size = 1) rgb_plot asia <- rast(system.file(\"extdata/asia.tif\", package = \"tidyterra\")) asia #> class : SpatRaster #> dimensions : 164, 306, 1 (nrow, ncol, nlyr) #> resolution : 31836.23, 31847.57 (x, y) #> extent : 7619120, 17361007, -1304745, 3918256 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source : asia.tif #> name : file44bc291153f2 #> min value : -9558.468 #> max value : 5801.927 ggplot() + geom_spatraster(data = asia) + scale_fill_hypso_tint_c( palette = \"gmt_globe\", labels = scales::label_number(), # Further refinements breaks = c(-10000, -5000, 0, 2000, 5000, 8000), guide = guide_colorbar(reverse = TRUE) ) + labs( fill = \"elevation (m)\", title = \"Hypsometric map of Asia\" ) + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"spatvectors-1","dir":"Articles","previous_headings":"Plotting with ggplot2","what":"SpatVectors","title":"Welcome to tidyterra","text":"tidyterra allows plot SpatVectors ggplot2 using geom_spatvector() functions: Plotting SpatVectors underlying implementation take advantage conversion terra::vect()/sf::st_as_sf() use ggplot2::geom_sf() endpoint creating layer. tidyterra can also aggregate SpatVectors convenience: Union SpatVectors Union SpatVector keeping inner borders","code":"lux <- system.file(\"ex/lux.shp\", package = \"terra\") v_lux <- terra::vect(lux) ggplot(v_lux) + geom_spatvector(aes(fill = POP), color = \"white\") + geom_spatvector_text(aes(label = NAME_2), color = \"grey90\") + scale_fill_binned(labels = scales::number_format()) + coord_sf(crs = 3857) # Dissolving v_lux %>% # Create categories mutate(gr = cut(POP / 1000, 5)) %>% group_by(gr) %>% # Summary summarise( n = n(), tot_pop = sum(POP), mean_area = mean(AREA) ) %>% ggplot() + geom_spatvector(aes(fill = tot_pop), color = \"black\") + geom_spatvector_label(aes(label = gr)) + coord_sf(crs = 3857) # Same but keeping internal boundaries v_lux %>% # Create categories mutate(gr = cut(POP / 1000, 5)) %>% group_by(gr) %>% # Summary without dissolving summarise( n = n(), tot_pop = sum(POP), mean_area = mean(AREA), .dissolve = FALSE ) %>% ggplot() + geom_spatvector(aes(fill = tot_pop), color = \"black\") + geom_spatvector_label(aes(label = gr)) + coord_sf(crs = 3857)"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Diego Hernangómez. Author, maintainer, copyright holder. Dewey Dunnington. Contributor. ggspatial code ggplot2 authors. Copyright holder. contour code","code":""},{"path":"https://dieghernan.github.io/tidyterra/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Hernangómez D (2023). “Using tidyverse terra objects: tidyterra package.” Journal Open Source Software, 8(91), 5751. ISSN 2475-9066, doi:10.21105/joss.05751, https://doi.org/10.21105/joss.05751.","code":"@Article{R-tidyterra, title = {Using the {tidyverse} with {terra} objects: the {tidyterra} package}, doi = {10.21105/joss.05751}, author = {Diego Hernangómez}, year = {2023}, url = {https://doi.org/10.21105/joss.05751}, publisher = {The Open Journal}, volume = {8}, number = {91}, pages = {5751}, journal = {Journal of Open Source Software}, issn = {2475-9066}, }"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement diego.hernangomezherrero@gmail.com. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"fixing-typos","dir":"","previous_headings":"","what":"Fixing typos","title":"CONTRIBUTING","text":"Small typos grammatical errors documentation may edited directly using GitHub web interface, long changes made source file. YES: edit roxygen comment .R file R/. : edit .Rd file man/.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"prerequisites","dir":"","previous_headings":"","what":"Prerequisites","title":"CONTRIBUTING","text":"make substantial pull request, always file issue make sure someone team agrees ’s problem. ’ve found bug, create associated issue illustrate bug minimal reprex.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"pull-request-process","dir":"","previous_headings":"","what":"Pull request process","title":"CONTRIBUTING","text":"recommend create Git branch pull request (PR). Look R-CMD-check build status making changes. recommend tidyverse style guide. can use styler package apply styles, please don’t restyle code nothing PR. use roxygen2. use testthat. Contributions test cases included easier accept. user-facing changes, add bullet top NEWS.md current development version header describing changes made followed GitHub username, links relevant issue(s)/PR(s).","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"prefer-to-email","dir":"","previous_headings":"","what":"Prefer to Email?","title":"CONTRIBUTING","text":"Email person listed maintainer DESCRIPTION file repo. Though note private discussions email don’t help others - course email totally warranted ’s sensitive problem kind.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"thanks-for-contributing","dir":"","previous_headings":"","what":"Thanks for contributing!","title":"CONTRIBUTING","text":"contributing guide adapted tidyverse contributing guide available https://raw.githubusercontent.com/r-lib/usethis/master/inst/templates/tidy-contributing.md","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"tidyterra-","dir":"","previous_headings":"","what":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"goal tidyterra provide common methods tidyverse packages objects created terra package: SpatRaster SpatVector. also provides geoms plotting objects ggplot2. Please cite tidyterra : Hernangómez, D., (2023). Using tidyverse terra objects: tidyterra package. Journal Open Source Software, 8(91), 5751, https://doi.org/10.21105/joss.05751. BibTeX entry LaTeX users :","code":"@article{Hernangómez2023, doi = {10.21105/joss.05751}, url = {https://doi.org/10.21105/joss.05751}, year = {2023}, publisher = {The Open Journal}, volume = {8}, number = {91}, pages = {5751}, author = {Diego Hernangómez}, title = {Using the {tidyverse} with {terra} objects: the {tidyterra} package}, journal = {Journal of Open Source Software} }"},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Full manual recent release tidyterra CRAN online: https://dieghernan.github.io/tidyterra/ tidyverse methods implemented tidyterra works differently depending type Spat* object: SpatVector: methods implemented using terra::.data.frame() coercion. Rows correspond geometries columns correspond attributes geometry. SpatRaster: implementation SpatRaster objects differs, since methods applied layers cells. tidyterra overall approach treat layers columns tibble cells rows (.e. select(SpatRaster, 1) select first layer SpatRaster). methods implemented return type object used input, unless expected behavior method return another type object, (example, as_tibble() return tibble). Current methods functions provided tidyterra :","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"exclamation-a-note-on-performance","dir":"","previous_headings":"","what":"❗ A note on performance","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"tidyterra conceived user-friendly wrapper terra using tidyverse methods verbs. approach therefore cost terms performance. heavy user terra need work big raster files, terra much focused terms performance. possible, function tidyterra references equivalent terra. rule thumb raster less 10.000.000 data slots counting cells layers (.e. terra::ncell(your_rast)*terra::nlyr(your_rast) < 10e6) good go tidyterra. plotting rasters, resampling performed automatically (terra::plot() , see help page). can adjust maxcell parameter.","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Install tidyterra CRAN: can install development version tidyterra like : Alternatively, can install tidyterra using r-universe:","code":"install.packages(\"tidyterra\") remotes::install_github(\"dieghernan/tidyterra\") # Enable this universe install.packages(\"tidyterra\", repos = c( \"https://dieghernan.r-universe.dev\", \"https://cloud.r-project.org\" ))"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"spatrasters","dir":"","previous_headings":"Example","what":"SpatRasters","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"basic example shows manipulate plot SpatRaster objects: tidyterra also provide geom plotting RGB SpatRaster tiles ggplot2 tidyterra provides specific scales plotting hypsometric maps ggplot2:","code":"library(tidyterra) library(terra) # Temperatures rastertemp <- rast(system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\")) rastertemp #> class : SpatRaster #> dimensions : 87, 118, 3 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source : cyl_temp.tif #> names : tavg_04, tavg_05, tavg_06 #> min values : 1.885463, 5.817587, 10.46338 #> max values : 13.283829, 16.740898, 21.11378 # Rename rastertemp <- rastertemp %>% rename(April = tavg_04, May = tavg_05, June = tavg_06) # Facet all layers library(ggplot2) ggplot() + geom_spatraster(data = rastertemp) + facet_wrap(~lyr, ncol = 2) + scale_fill_whitebox_c( palette = \"muted\", labels = scales::label_number(suffix = \"º\"), n.breaks = 12, guide = guide_legend(reverse = TRUE) ) + labs( fill = \"\", title = \"Average temperature in Castille and Leon (Spain)\", subtitle = \"Months of April, May and June\" ) # Create maximum differences of two months variation <- rastertemp %>% mutate(diff = June - May) %>% select(variation = diff) # Add also a overlay of a SpatVector prov <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) ggplot(prov) + geom_spatraster(data = variation) + geom_spatvector(fill = NA) + scale_fill_whitebox_c( palette = \"deep\", direction = -1, labels = scales::label_number(suffix = \"º\"), n.breaks = 5 ) + theme_minimal() + coord_sf(crs = 25830) + labs( fill = \"variation\", title = \"Variation of temperature in Castille and Leon (Spain)\", subtitle = \"Average temperatures in June vs. May\" ) rgb_tile <- rast(system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\")) plot <- ggplot(prov) + geom_spatraster_rgb(data = rgb_tile) + geom_spatvector(fill = NA) + theme_light() plot # Recognizes coord_sf() plot + # Change crs and datum (for relabeling graticules) coord_sf(crs = 3857, datum = 3857) asia <- rast(system.file(\"extdata/asia.tif\", package = \"tidyterra\")) terra::plot(asia) ggplot() + geom_spatraster(data = asia) + scale_fill_hypso_tint_c( palette = \"gmt_globe\", labels = scales::label_number(), # Further refinements breaks = c(-10000, -5000, 0, 2000, 5000, 8000), guide = guide_colorbar(reverse = TRUE) ) + labs( fill = \"elevation (m)\", title = \"Hypsometric map of Asia\" ) + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" )"},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"spatvectors","dir":"","previous_headings":"Example","what":"SpatVectors","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"basic example shows manipulate plot SpatVector objects:","code":"vect(system.file(\"ex/lux.shp\", package = \"terra\")) %>% mutate(pop_dens = POP / AREA) %>% glimpse() %>% autoplot(aes(fill = pop_dens)) + scale_fill_whitebox_c(palette = \"pi_y_g\") + labs( fill = \"population per km2\", title = \"Population density of Luxembourg\", subtitle = \"By canton\" ) #> # A SpatVector 12 x 7 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 44' 38.9\" E / 6° 31' 41.71\" E] , [49° 26' 52.11\" N / 50° 10' 53.84\" N]) #> #> $ ID_1 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3 #> $ NAME_1 \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Diekirch\", \"… #> $ ID_2 1, 2, 3, 4, 5, 6, 7, 12, 8, 9, 10, 11 #> $ NAME_2 \"Clervaux\", \"Diekirch\", \"Redange\", \"Vianden\", \"Wiltz\", \"Echte… #> $ AREA 312, 218, 259, 76, 263, 188, 129, 210, 185, 251, 237, 233 #> $ POP 18081, 32543, 18664, 5163, 16735, 18899, 22366, 29828, 48187,… #> $ pop_dens 57.95192, 149.27982, 72.06178, 67.93421, 63.63118, 100.52660,…"},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"i-need-your-feedback","dir":"","previous_headings":"","what":"I need your feedback","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Please leave feedback open issue https://github.com/dieghernan/tidyterra/issues.","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"need-help","dir":"","previous_headings":"","what":"Need help?","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Check FAQs open new issue! can also ask Stack Overflow using tag [tidyterra].","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"acknowledgement","dir":"","previous_headings":"","what":"Acknowledgement","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"tidyterra ggplot2 geoms based ggspatial implementation, Dewey Dunnington ggspatial contributors.","code":""},{"path":"https://dieghernan.github.io/tidyterra/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2022 tidyterra authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Order a SpatVector using column values — arrange.SpatVector","title":"Order a SpatVector using column values — arrange.SpatVector","text":"arrange.SpatVector() orders geometries SpatVector values selected columns.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Order a SpatVector using column values — arrange.SpatVector","text":"","code":"# S3 method for class 'SpatVector' arrange(.data, ..., .by_group = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Order a SpatVector using column values — arrange.SpatVector","text":".data SpatVector created terra::vect(). ... Variables, functions variables. Use desc() sort variable descending order. .by_group TRUE, sort first grouping variable. Applies grouped SpatVector (see group_by.SpatVector()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Order a SpatVector using column values — arrange.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Order a SpatVector using column values — arrange.SpatVector","text":"terra::sort()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Order a SpatVector using column values — arrange.SpatVector","text":"Implementation generic dplyr::arrange() function SpatVector class.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Order a SpatVector using column values — arrange.SpatVector","text":"","code":"library(terra) #> terra 1.8.5 library(dplyr) #> #> Attaching package: 'dplyr' #> The following objects are masked from 'package:terra': #> #> intersect, union #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) # Single variable v %>% arrange(desc(iso2)) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-ZA 49 Zamora #> ES-VA 47 Valladolid #> ES-SO 42 Soria # Two variables v %>% mutate(even = as.double(cpro) %% 2 == 0, ) %>% arrange(desc(even), desc(iso2)) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 4 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name even #> type : #> values : ES-SO 42 Soria TRUE #> ES-SG 40 Segovia TRUE #> ES-P 34 Palencia TRUE # With new variables v %>% mutate(area_geom = terra::expanse(v)) %>% arrange(area_geom) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 4 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name area_geom #> type : #> values : ES-SG 40 Segovia 6.921e+09 #> ES-P 34 Palencia 8.042e+09 #> ES-AV 05 Avila 8.053e+09"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":null,"dir":"Reference","previous_headings":"","what":"Get cell number, row and column from a SpatRaster — as_coordinates","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"as_coordinates() can used obtain position cell SpatRaster matrix.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"","code":"as_coordinates(x, as.raster = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"x SpatRaster object. .raster TRUE, result SpatRaster object three layers indicating position cell (cell number, row column).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"tibble SpatRaster (.raster = TRUE) number rows (cells) number cells x. .raster = TRUE resulting SpatRaster crs, extension resolution x","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) as_coordinates(r) #> # A tibble: 10,266 × 3 #> cellindex rowindex colindex #> #> 1 1 1 1 #> 2 2 1 2 #> 3 3 1 3 #> 4 4 1 4 #> 5 5 1 5 #> 6 6 1 6 #> 7 7 1 7 #> 8 8 1 8 #> 9 9 1 9 #> 10 10 1 10 #> # ℹ 10,256 more rows as_coordinates(r, as.raster = TRUE) #> class : SpatRaster #> dimensions : 87, 118, 3 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source(s) : memory #> names : cellindex, rowindex, colindex #> min values : 1, 1, 1 #> max values : 10266, 87, 118 as_coordinates(r, as.raster = TRUE) %>% plot()"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce a SpatVector to a sf object — as_sf","title":"Coerce a SpatVector to a sf object — as_sf","text":"as_sf() turns SpatVector sf object. wrapper sf::st_as_sf() particularity groups created group_by.SpatVector() preserved.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce a SpatVector to a sf object — as_sf","text":"","code":"as_sf(x, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce a SpatVector to a sf object — as_sf","text":"x SpatVector. ... additional arguments passed sf::st_as_sf().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerce a SpatVector to a sf object — as_sf","text":"sf object object additional tbl_df class, pretty printing method.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce a SpatVector to a sf object — as_sf","text":"","code":"library(terra) f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- terra::vect(f) # This is ungrouped v #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos #> ES-LE 24 Leon is_grouped_spatvector(v) #> [1] FALSE # Get an ungrouped data a_sf <- as_sf(v) dplyr::is_grouped_df(a_sf) #> [1] FALSE # Grouped v$gr <- c(\"C\", \"A\", \"A\", \"B\", \"A\", \"B\", \"B\") v$gr2 <- rep(c(\"F\", \"G\", \"F\"), 3) gr_v <- group_by(v, gr, gr2) gr_v #> class : SpatVector #> geometry : polygons #> dimensions : 9, 5 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name gr gr2 #> type : #> values : ES-AV 05 Avila C F #> ES-BU 09 Burgos A G #> ES-LE 24 Leon A F is_grouped_spatvector(gr_v) #> [1] TRUE group_data(gr_v) #> # A tibble: 5 × 3 #> gr gr2 .rows #> > #> 1 A F [2] #> 2 A G [2] #> 3 B F [3] #> 4 C F [1] #> 5 C G [1] # A sf a_gr_sf <- as_sf(gr_v) dplyr::is_grouped_df(a_gr_sf) #> [1] TRUE group_data(a_gr_sf) #> # A tibble: 5 × 3 #> gr gr2 .rows #> > #> 1 A F [2] #> 2 A G [2] #> 3 B F [3] #> 4 C F [1] #> 5 C G [1]"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce a data frame to SpatRaster — as_spatraster","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"as_spatraster() turns existing data frame tibble SpatRaster. wrapper terra::rast() S4 method signature data.frame.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"","code":"as_spatraster(x, ..., xycols = 1:2, crs = \"\", digits = 6)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"x tibble data frame. ... additional arguments passed terra::rast(). xycols vector integers length 2 determining position columns hold x y coordinates. crs crs several formats (PROJ.4, WKT, EPSG code, ..) spatial object sf terra. includes target coordinate reference system. See pull_crs() Details. digits integer set precision detecting whether points regular grid (low number digits low precision).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"SpatRaster.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"crs provided tibble created method as_tibble.SpatRaster(), crs inferred attr(x, \"crs\").","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"terra::rast() (see S4 method signature data.frame).","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"","code":"library(terra) r <- rast(matrix(1:90, ncol = 3), crs = \"EPSG:3857\") r #> class : SpatRaster #> dimensions : 30, 3, 1 (nrow, ncol, nlyr) #> resolution : 1, 1 (x, y) #> extent : 0, 3, 0, 30 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> name : lyr.1 #> min value : 1 #> max value : 90 # Create tibble as_tbl <- as_tibble(r, xy = TRUE) as_tbl #> # A tibble: 90 × 3 #> x y lyr.1 #> #> 1 0.5 29.5 1 #> 2 1.5 29.5 31 #> 3 2.5 29.5 61 #> 4 0.5 28.5 2 #> 5 1.5 28.5 32 #> 6 2.5 28.5 62 #> 7 0.5 27.5 3 #> 8 1.5 27.5 33 #> 9 2.5 27.5 63 #> 10 0.5 26.5 4 #> # ℹ 80 more rows # From tibble newrast <- as_spatraster(as_tbl, crs = \"EPSG:3857\") newrast #> class : SpatRaster #> dimensions : 30, 3, 1 (nrow, ncol, nlyr) #> resolution : 1, 1 (x, y) #> extent : 0, 3, 0, 30 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> name : lyr.1 #> min value : 1 #> max value : 90"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":null,"dir":"Reference","previous_headings":"","what":"Method for coercing objects to SpatVector — as_spatvector","title":"Method for coercing objects to SpatVector — as_spatvector","text":"as_spatvector() turns existing object SpatVector. wrapper terra::vect() S4 method signature data.frame.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Method for coercing objects to SpatVector — as_spatvector","text":"","code":"as_spatvector(x, ...) # S3 method for class 'data.frame' as_spatvector(x, ..., geom = c(\"lon\", \"lat\"), crs = \"\") # S3 method for class 'sf' as_spatvector(x, ...) # S3 method for class 'sfc' as_spatvector(x, ...) # S3 method for class 'SpatVector' as_spatvector(x, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Method for coercing objects to SpatVector — as_spatvector","text":"x tibble, data frame sf object class sf sfc. ... additional arguments passed terra::vect(). geom character. field name(s) geometry data. Either two names x y coordinates points, single name single column WKT geometries. crs crs several formats (PROJ.4, WKT, EPSG code, ..) spatial object sf terra includes target coordinate reference system. See pull_crs() Details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Method for coercing objects to SpatVector — as_spatvector","text":"SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Method for coercing objects to SpatVector — as_spatvector","text":"function differs terra::vect() following: geometries NA \"\" values removed prior conversion x grouped data frame (see dplyr::group_by()) grouping vars transferred \"grouped\" SpatVector created (see group_by.SpatVector()). crs provided tibble created method as_tibble.SpatVector(), crs inferred attr(x, \"crs\"). Handles correctly conversion EMPTY geometries sf terra.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Method for coercing objects to SpatVector — as_spatvector","text":"terra::vect()","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Method for coercing objects to SpatVector — as_spatvector","text":"","code":"library(terra) v <- vect(matrix(1:80, ncol = 2), crs = \"EPSG:3857\") v$cat <- sample(LETTERS[1:4], size = nrow(v), replace = TRUE) v #> class : SpatVector #> geometry : points #> dimensions : 40, 1 (geometries, attributes) #> extent : 1, 40, 41, 80 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> names : cat #> type : #> values : A #> C #> D # Create tibble as_tbl <- as_tibble(v, geom = \"WKT\") as_tbl #> # A tibble: 40 × 2 #> cat geometry #> #> 1 A POINT (1 41) #> 2 C POINT (2 42) #> 3 D POINT (3 43) #> 4 C POINT (4 44) #> 5 A POINT (5 45) #> 6 B POINT (6 46) #> 7 C POINT (7 47) #> 8 C POINT (8 48) #> 9 C POINT (9 49) #> 10 D POINT (10 50) #> # ℹ 30 more rows # From tibble newvect <- as_spatvector(as_tbl, geom = \"geometry\", crs = \"EPSG:3857\") newvect #> class : SpatVector #> geometry : points #> dimensions : 40, 1 (geometries, attributes) #> extent : 1, 40, 41, 80 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> names : cat #> type : #> values : A #> C #> D"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"as_tibble() methods SpatRaster SpatVector objects.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"","code":"# S3 method for class 'SpatRaster' as_tibble(x, ..., xy = FALSE, na.rm = FALSE, .name_repair = \"unique\") # S3 method for class 'SpatVector' as_tibble(x, ..., geom = NULL, .name_repair = \"unique\")"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"x SpatRaster created terra::rast() SpatVector created terra::vect(). ... Arguments passed terra::.data.frame(). xy logical. TRUE, coordinates raster cell included na.rm logical. TRUE, cells NA value least one layer removed. argument set NA cells NA values layers removed .name_repair Treatment problematic column names: \"minimal\": name repair checks, beyond basic existence. \"unique\": Make sure names unique empty. \"check_unique\": (default value), name repair, check unique. \"universal\": Make names unique syntactic. function: apply custom name repair (e.g., .name_repair = make.names names style base R). purrr-style anonymous function, see rlang::as_function(). geom character NULL. NULL, either \"WKT\" \"HEX\", get geometry included Well-Known-Text hexadecimal notation. x point geometry, can also \"XY\" add coordinates point","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"tibble.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"terra::.data.frame()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"Implementation generic tibble::as_tibble() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"spatraster-and-spatvector","dir":"Reference","previous_headings":"","what":"SpatRaster and SpatVector","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"tibble returned attribute including crs initial object WKT format (see pull_crs()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"about-layer-column-names","dir":"Reference","previous_headings":"","what":"About layer/column names","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"coercing SpatRaster objects data frames, x y names reserved geographic coordinates cell SpatRaster also noted terra allows layers duplicated names. process coercing SpatRaster tibble, tidyterra may rename layers SpatRaster overcoming issue. Specifically, layers may renamed following cases: Layers duplicated names. coercing tibble, xy = TRUE, layers named x y renamed. working tidyverse methods (.e. filter.SpatRaster()), latter happen well. tidyterra display message informing changes names layer. issue happens SpatVector names geometry (geom = c(\"WKT\", \"HEX\")) x, y (geom = \"XY\"). reserved names representing geometry SpatVector (see terra::.data.frame()). geom NULL logic described SpatRaster apply well columns SpatVector.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"","code":"library(terra) # SpatRaster f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) as_tibble(r, na.rm = TRUE) #> # A tibble: 6,522 × 3 #> tavg_04 tavg_05 tavg_06 #> #> 1 3.18 6.79 11.1 #> 2 5.30 8.73 12.7 #> 3 4.59 8.05 12.1 #> 4 6.38 9.72 13.6 #> 5 4.05 7.58 11.8 #> 6 2.90 6.54 10.9 #> 7 5.05 8.49 12.5 #> 8 2.58 6.17 10.5 #> 9 9.30 12.5 15.4 #> 10 9.84 13.0 15.9 #> # ℹ 6,512 more rows as_tibble(r, xy = TRUE) #> # A tibble: 10,266 × 5 #> x y tavg_04 tavg_05 tavg_06 #> #> 1 -610395. 4618746. NA NA NA #> 2 -606513. 4618746. NA NA NA #> 3 -602632. 4618746. NA NA NA #> 4 -598751. 4618746. NA NA NA #> 5 -594870. 4618746. NA NA NA #> 6 -590988. 4618746. NA NA NA #> 7 -587107. 4618746. NA NA NA #> 8 -583226. 4618746. NA NA NA #> 9 -579345. 4618746. NA NA NA #> 10 -575463. 4618746. NA NA NA #> # ℹ 10,256 more rows # SpatVector f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- vect(f) as_tibble(v) #> # A tibble: 9 × 3 #> iso2 cpro name #> #> 1 ES-AV 05 Avila #> 2 ES-BU 09 Burgos #> 3 ES-LE 24 Leon #> 4 ES-P 34 Palencia #> 5 ES-SA 37 Salamanca #> 6 ES-SG 40 Segovia #> 7 ES-SO 42 Soria #> 8 ES-VA 47 Valladolid #> 9 ES-ZA 49 Zamora"},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a complete ggplot for Spat* objects — autoplot.Spat","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"autoplot() uses ggplot2 draw plots ones produced terra::plot()/terra::plotRGB() single command.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"","code":"# S3 method for class 'SpatRaster' autoplot( object, ..., rgb = NULL, use_coltab = NULL, facets = NULL, nrow = NULL, ncol = 2 ) # S3 method for class 'SpatVector' autoplot(object, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"object SpatRaster created terra::rast() SpatVector created terra::vect(). ... arguments passed geom_spatraster(), geom_spatraster_rgb() geom_spatvector(). rgb Logical. plotted RGB image? NULL (default) autoplot.SpatRaster() try guess. use_coltab Logical. plotted corresponding terra::coltab()? NULL (default) autoplot.SpatRaster() try guess. See also scale_fill_coltab(). facets Logical. facets displayed? NULL (default) autoplot.SpatRaster() try guess. nrow, ncol Number rows columns facet.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Implementation ggplot2::autoplot() method.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Implementation generic ggplot2::autoplot() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Uses geom_spatraster() geom_spatraster_rgb().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Uses geom_spatvector(). Labels can placed geom_spatvector_text() geom_spatvector_label().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"","code":"# \\donttest{ file_path <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") library(terra) temp <- rast(file_path) library(ggplot2) autoplot(temp) # With a tile tile <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") %>% rast() autoplot(tile) # With coltabs ctab <- system.file(\"extdata/cyl_era.tif\", package = \"tidyterra\") %>% rast() autoplot(ctab) # With vectors v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) autoplot(v) v %>% autoplot(aes(fill = cpro)) + geom_spatvector_text(aes(label = iso2)) + coord_sf(crs = 25829) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"Bind number SpatVector, data frames sf object column, making wider result. similar .call(cbind, dfs). possible prefer using join combine SpatVector data frames objects. bind_spat_cols() binds rows order appear easy create meaningless results without realizing .","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"","code":"bind_spat_cols( ..., .name_repair = c(\"unique\", \"universal\", \"check_unique\", \"minimal\") )"},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"... Objects combine. first argument SpatVector subsequent arguments can either SpatVector, sf object data frame. Inputs recycled length, matched position. .name_repair One \"unique\", \"universal\", \"check_unique\". See dplyr::bind_cols() Details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"SpatVector corresponding columns. geometry CRS correspond first SpatVector ....","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"cbind() method","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"Implementation dplyr::bind_rows() function SpatVector objects. Note second subsequent arguments ... geometry cbinded, data frame (-ish) columns kept.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"","code":"library(terra) sv <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) df2 <- data.frame(letters = letters[seq_len(nrow(sv))]) # Data frame bind_spat_cols(sv, df2) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 4 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name letters #> type : #> values : ES-AV 05 Avila a #> ES-BU 09 Burgos b #> ES-LE 24 Leon c # Another SpatVector bind_spat_cols(sv[1:2, ], sv[3:4, ]) #> New names: #> • `iso2` -> `iso2...1` #> • `cpro` -> `cpro...2` #> • `name` -> `name...3` #> • `iso2` -> `iso2...4` #> • `cpro` -> `cpro...5` #> • `name` -> `name...6` #> class : SpatVector #> geometry : polygons #> dimensions : 2, 6 (geometries, attributes) #> extent : 2987054, 3296229, 2017622, 2331004 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2...1 cpro...2 name...3 iso2...4 cpro...5 name...6 #> type : #> values : ES-AV 05 Avila ES-LE 24 Leon #> ES-BU 09 Burgos ES-P 34 Palencia # sf objects sfobj <- sf::read_sf(system.file(\"shape/nc.shp\", package = \"sf\")) bind_spat_cols(sv[1:9, ], sfobj[1:9, ]) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 17 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name AREA PERIMETER CNTY_ CNTY_ID NAME FIPS #> type : #> values : ES-AV 05 Avila 0.114 1.442 1825 1825 Ashe 37009 #> ES-BU 09 Burgos 0.061 1.231 1827 1827 Alleghany 37005 #> ES-LE 24 Leon 0.143 1.63 1828 1828 Surry 37171 #> FIPSNO (and 7 more) #> #> 3.701e+04 #> 3.7e+04 #> 3.717e+04 # Mixed end <- bind_spat_cols(sv, sfobj[seq_len(nrow(sv)), 1:2], df2) end #> class : SpatVector #> geometry : polygons #> dimensions : 9, 6 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name AREA PERIMETER letters #> type : #> values : ES-AV 05 Avila 0.114 1.442 a #> ES-BU 09 Burgos 0.061 1.231 b #> ES-LE 24 Leon 0.143 1.63 c glimpse(end) #> # A SpatVector 9 x 6 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\"… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia… #> $ AREA 0.114, 0.061, 0.143, 0.070, 0.153, 0.097, 0.062, 0.091, 0.118 #> $ PERIMETER 1.442, 1.231, 1.630, 2.968, 2.206, 1.670, 1.547, 1.284, 1.421 #> $ letters \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\" # Row sizes must be compatible when column-binding try(bind_spat_cols(sv, sfobj)) #> Error in dplyr::bind_cols(alltibbs, .name_repair = .name_repair) : #> Can't recycle `..1` (size 9) to match `..2` (size 100)."},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"Bind number SpatVector, data frames sf/sfc objects row, making longer result. similar .call(rbind, dfs), output contain columns appear inputs.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"","code":"bind_spat_rows(..., .id = NULL)"},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"... Objects combine. first argument SpatVector subsequent arguments can either SpatVector, sf/sfc object data frame. Columns matched name, missing columns filled NA. .id name optional identifier column. Provide string create output column identifies input. column use names available, otherwise use positions.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"SpatVector type first element ....","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"rbind() method","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"Implementation dplyr::bind_rows() function SpatVector objects. first element ... SpatVector. Subsequent elements may SpatVector, sf/sfc objects data frames: subsequent SpatVector/sf/sfc objects present different CRS first element, elements reprojected CRS first element message. element ... tibble/data frame rows cbinded empty geometries message.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"","code":"library(terra) v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) v1 <- v[1, \"cpro\"] v2 <- v[3:5, c(\"name\", \"iso2\")] # You can supply individual SpatVector as arguments: bind_spat_rows(v1, v2) #> class : SpatVector #> geometry : polygons #> dimensions : 4, 3 (geometries, attributes) #> extent : 2892687, 3180130, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE #> NA Palencia ES-P # When you supply a column name with the `.id` argument, a new # column is created to link each row to its original data frame bind_spat_rows(v1, v2, .id = \"id\") #> class : SpatVector #> geometry : polygons #> dimensions : 4, 4 (geometries, attributes) #> extent : 2892687, 3180130, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : id cpro name iso2 #> type : #> values : 1 05 NA NA #> 2 NA Leon ES-LE #> 2 NA Palencia ES-P # \\donttest{ # Use with sf sfobj <- sf::st_as_sf(v2[1, ]) sfobj #> Simple feature collection with 1 feature and 2 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 2926589 ymin: 2233673 xmax: 3125372 ymax: 2361600 #> Projected CRS: ETRS89-extended / LAEA Europe #> name iso2 geometry #> 1 Leon ES-LE POLYGON ((3049427 2233673, ... bind_spat_rows(v1, sfobj) #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2926589, 3126360, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE # Would reproject with a message on different CRS sfobj_3857 <- as_spatvector(sfobj) %>% project(\"EPSG:3857\") bind_spat_rows(v1, sfobj_3857) #> ! Reprojecting object 2 in `...` since it doesn't have the same CRS than object 1 #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2926589, 3126360, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE # And with data frames with a message data(\"mtcars\") bind_spat_rows(v1, sfobj, mtcars, .id = \"id2\") #> ! Object 3 in `...` is #> The result would present empty geoms #> class : SpatVector #> geometry : polygons #> dimensions : 34, 15 (geometries, attributes) #> extent : -180, 3126360, -90, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : id2 cpro name iso2 mpg cyl disp hp drat wt #> type : #> values : 1 05 NA NA NA NA NA NA NA NA #> 2 NA Leon ES-LE NA NA NA NA NA NA #> 3 NA NA NA 21 6 160 110 3.9 2.62 #> (and 5 more) #> #> #> #> # Use lists bind_spat_rows(list(v1[1, ], sfobj[1:2, ])) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 3 (geometries, attributes) #> extent : -180, 3126360, -90, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE #> NA NA NA # Or named list combined with .id bind_spat_rows(list( SpatVector = v1[1, ], sf = sfobj[1, ], mtcars = mtcars[1, ] ), .id = \"source\") #> ! Object 3 in `...` is #> The result would present empty geoms #> class : SpatVector #> geometry : polygons #> dimensions : 3, 15 (geometries, attributes) #> extent : -180, 3126360, -90, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : source cpro name iso2 mpg cyl disp hp drat wt #> type : #> values : SpatVector 05 NA NA NA NA NA NA NA NA #> sf NA Leon ES-LE NA NA NA NA NA NA #> mtcars NA NA NA 21 6 160 110 3.9 2.62 #> (and 5 more) #> #> #> #> # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":null,"dir":"Reference","previous_headings":"","what":"Compare attributes of two SpatRaster objects — compare_spatrasters","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"Two SpatRaster objects compatible (terms combining layers) crs, extent resolution similar. cases can combine objects simply c(x, y). function compares attributes informing results. See Solving issues section minimal guidance.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"","code":"compare_spatrasters(x, y, digits = 6)"},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"x, y SpatRaster objects digits Integer set precision comparing extent resolution.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"invisible logical TRUE/FALSE indicating SpatRaster objects compatible, plus informative message flagging issues found ().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"terra::identical()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"solving-issues","dir":"Reference","previous_headings":"","what":"Solving issues","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"non-equal crs, try terra::project(). non-equal extent try terra::resample(). non-equal resolution can try terra::resample(), terra::aggregate() terra::disagg().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"","code":"library(terra) x <- rast(matrix(1:90, ncol = 3), crs = \"EPSG:3857\") # Nothing compare_spatrasters(x, x) # Different crs y_nocrs <- x crs(y_nocrs) <- NA compare_spatrasters(x, y_nocrs) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • crs # Different extent compare_spatrasters(x, x[1:10, , drop = FALSE]) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • extent # Different resolution y_newres <- x res(y_newres) <- res(x) / 2 compare_spatrasters(x, y_newres) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • resolution # Everything compare_spatrasters(x, project(x, \"epsg:3035\")) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • crs #> • extent #> • resolution"},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Count the observations in each SpatVector group — count.SpatVector","title":"Count the observations in each SpatVector group — count.SpatVector","text":"count() lets quickly count unique values one variables: df %>% count(, b) roughly equivalent df %>% group_by(, b) %>% summarise(n = n()). count() paired tally(), lower-level helper equivalent df %>% summarise(n = n()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Count the observations in each SpatVector group — count.SpatVector","text":"","code":"# S3 method for class 'SpatVector' count( x, ..., wt = NULL, sort = FALSE, name = NULL, .drop = group_by_drop_default(x), .dissolve = TRUE ) # S3 method for class 'SpatVector' tally(x, wt = NULL, sort = FALSE, name = NULL)"},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Count the observations in each SpatVector group — count.SpatVector","text":"x SpatVector. ... Variables group . wt implemented method sort TRUE, show largest groups top. name name new column output. omitted, default n. already column called n, use nn. column called n nn, 'll use nnn, , adding ns gets new name. .drop Handling factor levels appear data, passed group_by(). count(): FALSE include counts empty groups (.e. levels factors exist data). add_count(): deprecated since actually affect output. .dissolve logical. borders aggregated geometries dissolved?","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Count the observations in each SpatVector group — count.SpatVector","text":"SpatVector object additional attribute.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Count the observations in each SpatVector group — count.SpatVector","text":"terra::aggregate()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Count the observations in each SpatVector group — count.SpatVector","text":"Implementation generic dplyr::count() family functions SpatVector objects. tally() always return disaggregated geometry count() can handle . See also summarise.SpatVector().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Count the observations in each SpatVector group — count.SpatVector","text":"","code":"# \\donttest{ library(terra) f <- system.file(\"ex/lux.shp\", package = \"terra\") p <- vect(f) p %>% count(NAME_1, sort = TRUE) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_1 n #> type : #> values : Diekirch 5 #> Luxembourg 4 #> Grevenmacher 3 p %>% count(NAME_1, sort = TRUE) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_1 n #> type : #> values : Diekirch 5 #> Luxembourg 4 #> Grevenmacher 3 p %>% count(pop = ifelse(POP < 20000, \"A\", \"B\")) #> class : SpatVector #> geometry : polygons #> dimensions : 2, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : pop n #> type : #> values : A 5 #> B 7 # tally() is a lower-level function that assumes you've done the grouping p %>% tally() #> class : SpatVector #> geometry : polygons #> dimensions : 1, 1 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : n #> type : #> values : 12 p %>% group_by(NAME_1) %>% tally() #> class : SpatVector #> geometry : polygons #> dimensions : 3, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_1 n #> type : #> values : Diekirch 5 #> Grevenmacher 3 #> Luxembourg 4 # Dissolve geometries by default library(ggplot2) p %>% count(NAME_1) %>% ggplot() + geom_spatvector(aes(fill = n)) # Opt out p %>% count(NAME_1, .dissolve = FALSE, sort = TRUE) %>% ggplot() + geom_spatvector(aes(fill = n)) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/cross_blended_hypsometric_tints_db.html","id":null,"dir":"Reference","previous_headings":"","what":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","title":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","text":"tibble including color map 4 gradient palettes. palettes includes also definition colors limits terms elevation (meters), can used ggplot2::scale_fill_gradientn().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/cross_blended_hypsometric_tints_db.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","text":"tibble 41 rows 6 columns. following fields: pal Name palette. limit Recommended elevation limit (meters) color. r Value red channel (RGB color mode). g Value green channel (RGB color mode). b Value blue channel (RGB color mode). hex Hex code color.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/cross_blended_hypsometric_tints_db.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","text":"Derived : Patterson, T., & Jenny, B. (2011). Development Rationale Cross-blended Hypsometric Tints. Cartographic Perspectives, (69), 31 - 46. doi:10.14714/CP69.20 .","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/cross_blended_hypsometric_tints_db.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","text":"Patterson & Jenny (2011): recently, role design hypsometric tints come scrutiny. One reason concern people misread elevation colors climate vegetation information. Cross-blended hypsometric tints, introduced 2009, partial solution problem. use variable lowland colors customized match differing natural environments world regions, merge one another.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/cross_blended_hypsometric_tints_db.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","text":"","code":"# \\donttest{ data(\"cross_blended_hypsometric_tints_db\") cross_blended_hypsometric_tints_db #> # A tibble: 41 × 6 #> pal limit r g b hex #> #> 1 arid 0 160 152 141 #A0988D #> 2 arid 50 170 160 150 #AAA096 #> 3 arid 200 180 170 158 #B4AA9E #> 4 arid 600 202 190 174 #CABEAE #> 5 arid 1000 212 201 180 #D4C9B4 #> 6 arid 2000 212 184 163 #D4B8A3 #> 7 arid 3000 212 193 179 #D4C1B3 #> 8 arid 4000 212 207 204 #D4CFCC #> 9 arid 5000 220 220 220 #DCDCDC #> 10 arid 6000 235 235 237 #EBEBED #> # ℹ 31 more rows # Select a palette warm <- cross_blended_hypsometric_tints_db %>% filter(pal == \"warm_humid\") f <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") r <- terra::rast(f) library(ggplot2) p <- ggplot() + geom_spatraster(data = r) + labs(fill = \"elevation\") p + scale_fill_gradientn(colors = warm$hex) # Use with limits p + scale_fill_gradientn( colors = warm$hex, values = scales::rescale(warm$limit), limit = range(warm$limit), na.value = \"lightblue\" ) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"Keep unique/distinct rows geometries SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"","code":"# S3 method for class 'SpatVector' distinct(.data, ..., .keep_all = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":".data SpatVector created terra::vect(). ... Optional variables use determining uniqueness. multiple rows given combination inputs, first row preserved. omitted, use variables data frame. reserved variable name, geometry, remove duplicate geometries. See Methods. .keep_all TRUE, keep variables .data. combination ... distinct, keeps first row values.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"terra::unique()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"Implementation generic dplyr::distinct() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"possible remove duplicate geometries including geometry variable explicitly ... call. See Examples.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"","code":"library(terra) v <- vect(system.file(\"ex/lux.shp\", package = \"terra\")) # Create a vector with dups v <- v[sample(seq_len(nrow(v)), 100, replace = TRUE), ] v$gr <- sample(LETTERS[1:3], 100, replace = TRUE) # All duplicates ex1 <- distinct(v) ex1 #> class : SpatVector #> geometry : polygons #> dimensions : 34, 7 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : ID_1 NAME_1 ID_2 NAME_2 AREA POP gr #> type : #> values : 1 Diekirch 5 Wiltz 263 1.674e+04 A #> 2 Grevenmacher 6 Echternach 188 1.89e+04 C #> 3 Luxembourg 8 Capellen 185 4.819e+04 A nrow(ex1) #> [1] 34 # Duplicates by NAME_1 ex2 <- distinct(v, gr) ex2 #> class : SpatVector #> geometry : polygons #> dimensions : 3, 1 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.72324, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : gr #> type : #> values : A #> C #> B nrow(ex2) #> [1] 3 # Same but keeping all cols ex2b <- distinct(v, gr, .keep_all = TRUE) ex2b #> class : SpatVector #> geometry : polygons #> dimensions : 3, 7 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.72324, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : gr ID_1 NAME_1 ID_2 NAME_2 AREA POP #> type : #> values : A 1 Diekirch 5 Wiltz 263 1.674e+04 #> C 2 Grevenmacher 6 Echternach 188 1.89e+04 #> B 1 Diekirch 1 Clervaux 312 1.808e+04 nrow(ex2b) #> [1] 3 # Unique geometries ex3 <- distinct(v, geometry) ex3 #> class : SpatVector #> geometry : polygons #> dimensions : 12, 0 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) nrow(ex3) #> [1] 12 # Same as terra::unique() terra::unique(ex3) #> class : SpatVector #> geometry : polygons #> dimensions : 12, 0 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) # Unique keeping info distinct(v, geometry, .keep_all = TRUE) #> class : SpatVector #> geometry : polygons #> dimensions : 12, 7 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : ID_1 NAME_1 ID_2 NAME_2 AREA POP gr #> type : #> values : 1 Diekirch 5 Wiltz 263 1.674e+04 A #> 2 Grevenmacher 6 Echternach 188 1.89e+04 C #> 3 Luxembourg 8 Capellen 185 4.819e+04 A"},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"SpatVector: drop_na() method drops geometries attribute specified ... contains missing value. SpatRaster: drop_na() method drops cells layer specified ... contains missing value.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"","code":"# S3 method for class 'SpatVector' drop_na(data, ...) # S3 method for class 'SpatRaster' drop_na(data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"data SpatVector created terra::vect() SpatRaster terra::rast(). ... Attributes inspect missing values. empty, attributes used.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"Spat* object class data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"terra::trim()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"Implementation generic tidyr::drop_na() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"implementation method performed -attribute basis, meaning NAs assessed attributes (columns) vector (rows). result SpatVector potentially less geometries input.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"Actual implementation drop_na().SpatRaster can understood masking method based values layers (see terra::mask()). SpatRaster layers considered columns SpatRaster cells rows, rows (cells) NA value layer get NA value. possible also mask cells (rows) based values specific layers (columns). drop_na() effectively remove outer cells NA (see terra::trim()), extent resulting object may differ extent input (see terra::resample() info). Check Examples better understanding method.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"feedback-needed-","dir":"Reference","previous_headings":"","what":"Feedback needed!","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"Visit https://github.com/dieghernan/tidyterra/issues. implementation method SpatRaster may change future.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- terra::vect(f) # Add NAs v <- v %>% mutate(iso2 = ifelse(cpro <= \"09\", NA, cpro)) # Init plot(v, col = \"red\") # Mask with lyr.1 v %>% drop_na(iso2) %>% plot(col = \"red\") # SpatRaster method # \\donttest{ r <- rast( crs = \"EPSG:3857\", extent = c(0, 10, 0, 10), nlyr = 3, resolution = c(2.5, 2.5) ) terra::values(r) <- seq_len(ncell(r) * nlyr(r)) # Add NAs r[r > 13 & r < 22 | r > 31 & r < 45] <- NA # Init plot(r, nc = 3) # Mask with lyr.1 r %>% drop_na(lyr.1) %>% plot(nc = 3) # Mask with lyr.2 r %>% drop_na(lyr.2) %>% plot(nc = 3) # Mask with lyr.3 r %>% drop_na(lyr.3) %>% plot(nc = 3) # Auto-mask all layers r %>% drop_na() %>% plot(nc = 3) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"Fills missing values selected columns using next previous entry. useful common output format values repeated, recorded change.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"","code":"# S3 method for class 'SpatVector' fill(data, ..., .direction = c(\"down\", \"up\", \"downup\", \"updown\"))"},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"data SpatVector. ... Columns fill. .direction Direction fill missing values. Currently either \"\" (default), \"\", \"downup\" (.e. first ) \"updown\" (first ).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"Implementation generic tidyr::fill() function SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"grouped-spatvector","dir":"Reference","previous_headings":"","what":"Grouped SpatVector","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"grouped SpatVector created group_by.SpatVector(), fill() applied within group, meaning fill across group boundaries.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"","code":"library(dplyr) lux <- terra::vect(system.file(\"ex/lux.shp\", package = \"terra\")) # Leave some blanks for demo purporses lux_blnk <- lux %>% mutate(NAME_1 = if_else(NAME_1 != NAME_2, NA, NAME_2)) as_tibble(lux_blnk) #> # A tibble: 12 × 6 #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 NA 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 NA 3 Redange 259 18664 #> 4 1 NA 4 Vianden 76 5163 #> 5 1 NA 5 Wiltz 263 16735 #> 6 2 NA 6 Echternach 188 18899 #> 7 2 NA 7 Remich 129 22366 #> 8 2 Grevenmacher 12 Grevenmacher 210 29828 #> 9 3 NA 8 Capellen 185 48187 #> 10 3 NA 9 Esch-sur-Alzette 251 176820 #> 11 3 Luxembourg 10 Luxembourg 237 182607 #> 12 3 NA 11 Mersch 233 32112 # `fill()` defaults to replacing missing data from top to bottom lux_blnk %>% fill(NAME_1) %>% as_tibble() #> # A tibble: 12 × 6 #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 NA 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 Diekirch 3 Redange 259 18664 #> 4 1 Diekirch 4 Vianden 76 5163 #> 5 1 Diekirch 5 Wiltz 263 16735 #> 6 2 Diekirch 6 Echternach 188 18899 #> 7 2 Diekirch 7 Remich 129 22366 #> 8 2 Grevenmacher 12 Grevenmacher 210 29828 #> 9 3 Grevenmacher 8 Capellen 185 48187 #> 10 3 Grevenmacher 9 Esch-sur-Alzette 251 176820 #> 11 3 Luxembourg 10 Luxembourg 237 182607 #> 12 3 Luxembourg 11 Mersch 233 32112 # direction = \"up\" lux_blnk %>% fill(NAME_1, .direction = \"up\") %>% as_tibble() #> # A tibble: 12 × 6 #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 Diekirch 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 Grevenmacher 3 Redange 259 18664 #> 4 1 Grevenmacher 4 Vianden 76 5163 #> 5 1 Grevenmacher 5 Wiltz 263 16735 #> 6 2 Grevenmacher 6 Echternach 188 18899 #> 7 2 Grevenmacher 7 Remich 129 22366 #> 8 2 Grevenmacher 12 Grevenmacher 210 29828 #> 9 3 Luxembourg 8 Capellen 185 48187 #> 10 3 Luxembourg 9 Esch-sur-Alzette 251 176820 #> 11 3 Luxembourg 10 Luxembourg 237 182607 #> 12 3 NA 11 Mersch 233 32112 # Grouping and downup - will restore the initial state lux_blnk %>% group_by(ID_1) %>% fill(NAME_1, .direction = \"downup\") %>% as_tibble() #> # A tibble: 12 × 6 #> # Groups: ID_1 [3] #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 Diekirch 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 Diekirch 3 Redange 259 18664 #> 4 1 Diekirch 4 Vianden 76 5163 #> 5 1 Diekirch 5 Wiltz 263 16735 #> 6 2 Grevenmacher 6 Echternach 188 18899 #> 7 2 Grevenmacher 7 Remich 129 22366 #> 8 2 Grevenmacher 12 Grevenmacher 210 29828 #> 9 3 Luxembourg 8 Capellen 185 48187 #> 10 3 Luxembourg 9 Esch-sur-Alzette 251 176820 #> 11 3 Luxembourg 10 Luxembourg 237 182607 #> 12 3 Luxembourg 11 Mersch 233 32112"},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Filtering joins for SpatVector objects — filter-joins.SpatVector","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"Filtering joins filter rows x based presence absence matches y: semi_join() return rows x match y. anti_join() return rows x without match y. See dplyr::semi_join() details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"","code":"# S3 method for class 'SpatVector' semi_join(x, y, by = NULL, copy = FALSE, ...) # S3 method for class 'SpatVector' anti_join(x, y, by = NULL, copy = FALSE, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"x SpatVector created terra::vect(). y data frame object coercible data frame. SpatVector sf object provided return error (see terra::intersect() performing spatial joins). join specification created join_by(), character vector variables join . NULL, default, *_join() perform natural join, using variables common across x y. message lists variables can check correct; suppress message supplying explicitly. join different variables x y, use join_by() specification. example, join_by(== b) match x$y$b. join multiple variables, use join_by() specification multiple expressions. example, join_by(== b, c == d) match x$y$b x$c y$d. column names x y, can shorten listing variable names, like join_by(, c). join_by() can also used perform inequality, rolling, overlap joins. See documentation ?join_by details types joins. simple equality joins, can alternatively specify character vector variable names join . example, = c(\"\", \"b\") joins x$y$x$b y$b. variable names differ x y, use named character vector like = c(\"x_a\" = \"y_a\", \"x_b\" = \"y_b\"). perform cross-join, generating combinations x y, see cross_join(). copy x y data source, copy TRUE, y copied src x. allows join tables across srcs, potentially expensive operation must opt . ... parameters passed onto methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"terra::merge()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"Implementation generic dplyr::semi_join() family","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"geometry column sticky behavior. means result always geometry x records matches join conditions.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"","code":"library(terra) library(ggplot2) # Vector v <- terra::vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) # A data frame df <- data.frame( cpro = sprintf(\"%02d\", 1:10), x = runif(10), y = runif(10), letter = rep_len(LETTERS[1:3], length.out = 10) ) v #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos #> ES-LE 24 Leon # Semi join semi <- v %>% semi_join(df) #> Joining with `by = join_by(cpro)` semi #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2987054, 3296229, 2017622, 2331004 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos autoplot(semi, aes(fill = iso2)) + ggtitle(\"Semi Join\") # Anti join anti <- v %>% anti_join(df) #> Joining with `by = join_by(cpro)` anti #> class : SpatVector #> geometry : polygons #> dimensions : 7, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2049224, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-LE 24 Leon #> ES-P 34 Palencia #> ES-SA 37 Salamanca autoplot(anti, aes(fill = iso2)) + ggtitle(\"Anti Join\")"},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Subset cells/geometries of Spat* objects — filter.Spat","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"filter() function used subset Spat* objects, retaining cells/geometries satisfy conditions. retained, cell/geometry must produce value TRUE conditions. possible filter SpatRaster geographic coordinates. need use filter(.data, x > 42). Note x y reserved names terra, since refer geographic coordinates layer. See Examples section layer names as_tibble.Spat().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"","code":"# S3 method for class 'SpatRaster' filter(.data, ..., .preserve = FALSE, .keep_extent = TRUE) # S3 method for class 'SpatVector' filter(.data, ..., .preserve = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... Expressions return logical value, defined terms layers/attributes .data. multiple expressions included, combined & operator. cells/geometries conditions evaluate TRUE kept. See Methods. .preserve Ignored Spat* objects. .keep_extent extent resulting SpatRaster kept? FALSE, terra::trim() called extent result may different extent output. See also drop_na.SpatRaster().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"Implementation generic dplyr::filter() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"Cells fulfill conditions ... returned value NA. multi-layer SpatRaster NA propagated across layers. .keep_extent = TRUE returning SpatRaster crs, extent, resolution hence number cells .data. .keep_extent = FALSE outer NA cells trimmed terra::trim(), extent number cells may differ. output present case crs resolution .data. x y variables (.e. longitude latitude SpatRaster) also available internally filtering. See Examples.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"result SpatVector geometries produce value TRUE conditions.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) %>% select(tavg_04) plot(r) # Filter temps r_f <- r %>% filter(tavg_04 > 11.5) # Extent is kept plot(r_f) # Filter temps and extent r_f2 <- r %>% filter(tavg_04 > 11.5, .keep_extent = FALSE) # Extent has changed plot(r_f2) # Filter by geographic coordinates r2 <- project(r, \"epsg:4326\") r2 %>% plot() r2 %>% filter( x > -4, x < -2, y > 42 ) %>% plot()"},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Fortify Spat* Objects — fortify.Spat","title":"Fortify Spat* Objects — fortify.Spat","text":"Fortify SpatRaster SpatVector objects data frames. provide native compatibility ggplot2::ggplot().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fortify Spat* Objects — fortify.Spat","text":"","code":"# S3 method for class 'SpatRaster' fortify( model, data, ..., .name_repair = \"unique\", maxcell = terra::ncell(model) * 1.1, pivot = FALSE ) # S3 method for class 'SpatVector' fortify(model, data, ...) # S3 method for class 'SpatGraticule' fortify(model, data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fortify Spat* Objects — fortify.Spat","text":"model SpatRaster created terra::rast() SpatVector created terra::vect(). data used method. ... arguments passed layer()'s params argument. arguments broadly fall one 4 categories . Notably, arguments position argument, aesthetics required can passed .... Unknown arguments part 4 categories ignored. Static aesthetics mapped scale, fixed value apply layer whole. example, colour = \"red\" linewidth = 3. geom's documentation Aesthetics section lists available options. 'required' aesthetics passed params. Please note passing unmapped aesthetics vectors technically possible, order required length guaranteed parallel input data. constructing layer using stat_*() function, ... argument can used pass parameters geom part layer. example stat_density(geom = \"area\", outline.type = \"\"). geom's documentation lists parameters can accept. Inversely, constructing layer using geom_*() function, ... argument can used pass parameters stat part layer. example geom_area(stat = \"density\", adjust = 0.5). stat's documentation lists parameters can accept. key_glyph argument layer() may also passed .... can one functions described key glyphs, change display layer legend. .name_repair Treatment problematic column names: \"minimal\": name repair checks, beyond basic existence. \"unique\": Make sure names unique empty. \"check_unique\": (default value), name repair, check unique. \"universal\": Make names unique syntactic. function: apply custom name repair (e.g., .name_repair = make.names names style base R). purrr-style anonymous function, see rlang::as_function(). maxcell positive integer. Maximum number cells use plot. pivot Logical. TRUE SpatRaster fortified long format. FALSE (default) fortified data frame column layer. See Details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fortify Spat* Objects — fortify.Spat","text":"fortify.SpatVector() returns sf object fortify.SpatRaster() returns tibble. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Fortify Spat* Objects — fortify.Spat","text":"Implementation generic ggplot2::fortify() method.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Fortify Spat* Objects — fortify.Spat","text":"Return tibble can used ggplot2::geom_* like ggplot2::geom_point(), ggplot2::geom_raster(), etc. resulting tibble includes coordinates columns x, y. values layer included additional columns named per name layer SpatRaster. CRS SpatRaster can retrieved attr(fortifiedSpatRaster, \"crs\"). possible convert fortified object onto SpatRaster as_spatraster(). pivot = TRUE SpatRaster fortified \"long\" format (see tidyr::pivot_longer()). fortified object following columns: x,y: Coordinates (center) cell corresponding CRS. lyr: Indicating name SpatRaster layer value. value: value SpatRaster corresponding lyr. option may useful using several geom_* faceting, see Examples.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"spatvector-and-spatgraticule","dir":"Reference","previous_headings":"","what":"SpatVector and SpatGraticule","title":"Fortify Spat* Objects — fortify.Spat","text":"Return sf object can used ggplot2::geom_sf().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fortify Spat* Objects — fortify.Spat","text":"","code":"# \\donttest{ # Get a SpatRaster r <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") %>% terra::rast() %>% terra::project(\"EPSG:4326\") fortified <- ggplot2::fortify(r) fortified #> # A tibble: 23,166 × 3 #> x y elevation #> #> 1 175. -36.9 NA #> 2 175. -36.9 NA #> 3 175. -36.9 NA #> 4 175. -36.9 NA #> 5 175. -36.9 NA #> 6 175. -36.9 NA #> 7 175. -36.9 NA #> 8 175. -36.9 NA #> 9 175. -36.9 NA #> 10 175. -36.9 NA #> # ℹ 23,156 more rows # The crs is an attribute of the fortified SpatRaster attr(fortified, \"crs\") #> [1] \"GEOGCRS[\\\"WGS 84\\\",\\n ENSEMBLE[\\\"World Geodetic System 1984 ensemble\\\",\\n MEMBER[\\\"World Geodetic System 1984 (Transit)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G730)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G873)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G1150)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G1674)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G1762)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G2139)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G2296)\\\"],\\n ELLIPSOID[\\\"WGS 84\\\",6378137,298.257223563,\\n LENGTHUNIT[\\\"metre\\\",1]],\\n ENSEMBLEACCURACY[2.0]],\\n PRIMEM[\\\"Greenwich\\\",0,\\n ANGLEUNIT[\\\"degree\\\",0.0174532925199433]],\\n CS[ellipsoidal,2],\\n AXIS[\\\"geodetic latitude (Lat)\\\",north,\\n ORDER[1],\\n ANGLEUNIT[\\\"degree\\\",0.0174532925199433]],\\n AXIS[\\\"geodetic longitude (Lon)\\\",east,\\n ORDER[2],\\n ANGLEUNIT[\\\"degree\\\",0.0174532925199433]],\\n USAGE[\\n SCOPE[\\\"Horizontal component of 3D system.\\\"],\\n AREA[\\\"World.\\\"],\\n BBOX[-90,-180,90,180]],\\n ID[\\\"EPSG\\\",4326]]\" # Back to a SpatRaster with as_spatraster(fortified) #> class : SpatRaster #> dimensions : 162, 143, 1 (nrow, ncol, nlyr) #> resolution : 4.916776e-05, 4.916772e-05 (x, y) #> extent : 174.7611, 174.7682, -36.87992, -36.87195 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> source(s) : memory #> name : elevation #> min value : 76.56599 #> max value : 195.50436 # You can now use a SpatRaster with any geom library(ggplot2) ggplot(r) + geom_histogram(aes(x = elevation), bins = 20, fill = \"lightblue\", color = \"black\" ) #> Warning: Removed 975 rows containing non-finite outside the scale range (`stat_bin()`). # ... and other packages # Use metR with facets library(metR) temp <- terra::rast(system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\" )) brks <- seq(0, 21, 3) # Fix breaks! # Pivot option for faceting ggplot(temp, aes(x, y), pivot = TRUE) + # tidyterra, don't inherit aes geom_spatraster_contour_filled( data = temp, inherit.aes = FALSE, breaks = brks ) + # metR geom_contour_tanaka(aes(z = value), breaks = brks) + facet_wrap(~lyr, nrow = 1) + scale_fill_whitebox_d(palette = \"muted\") + theme_minimal() + labs( title = \"tidyterra + metR\", subtitle = \"Facets\", fill = \"temp (°C)\", x = \"\", y = \"\" ) # Create a SpatVector extfile <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") cyl <- terra::vect(extfile) cyl #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos #> ES-LE 24 Leon # To sf ggplot2::fortify(cyl) #> Simple feature collection with 9 features and 3 fields #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 2892687 ymin: 2017622 xmax: 3341372 ymax: 2361600 #> Projected CRS: ETRS89-extended / LAEA Europe #> # A tibble: 9 × 4 #> iso2 cpro name geometry #> * #> 1 ES-AV 05 Avila POLYGON ((3126360 2066778, 3125074 2065007, 3124303 20… #> 2 ES-BU 09 Burgos MULTIPOLYGON (((3276731 2262326, 3275910 2265723, 3270… #> 3 ES-LE 24 Leon POLYGON ((3049427 2233673, 3049069 2234201, 3047819 22… #> 4 ES-P 34 Palencia MULTIPOLYGON (((3175411 2291868, 3175606 2293658, 3177… #> 5 ES-SA 37 Salamanca POLYGON ((3042661 2138939, 3043434 2140279, 3046345 21… #> 6 ES-SG 40 Segovia POLYGON ((3126360 2066778, 3124037 2067928, 3118421 20… #> 7 ES-SO 42 Soria POLYGON ((3194084 2154251, 3194362 2156613, 3195482 21… #> 8 ES-VA 47 Valladolid MULTIPOLYGON (((3158120 2161552, 3155455 2155198, 3149… #> 9 ES-ZA 49 Zamora POLYGON ((3042661 2138939, 3040851 2133391, 3038188 21… # Now you can use geom_sf() straight away thanks to fortify::SpatVector() library(ggplot2) ggplot(cyl) + geom_sf() # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":null,"dir":"Reference","previous_headings":"","what":"Visualise SpatRaster objects — geom_spatraster","title":"Visualise SpatRaster objects — geom_spatraster","text":"geom used visualise SpatRaster objects (see terra::rast()). geom designed visualise object layers, terra::plot() . plotting SpatRaster objects map tiles (.e. RGB SpatRaster), use geom_spatraster_rgb(). underlying implementation based ggplot2::geom_raster(). stat_spatraster() provided complementary function, geom can modified.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Visualise SpatRaster objects — geom_spatraster","text":"","code":"geom_spatraster( mapping = aes(), data, na.rm = TRUE, show.legend = NA, inherit.aes = FALSE, interpolate = FALSE, maxcell = 5e+05, use_coltab = TRUE, ... ) stat_spatraster( mapping = aes(), data, geom = \"raster\", na.rm = TRUE, show.legend = NA, inherit.aes = FALSE, maxcell = 5e+05, ... )"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Visualise SpatRaster objects — geom_spatraster","text":"Based layer_spatial() implementation ggspatial package. Thanks Dewey Dunnington ggspatial contributors.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Visualise SpatRaster objects — geom_spatraster","text":"mapping Set aesthetic mappings created ggplot2::aes(). See Aesthetics specially use fill aesthetic. data SpatRaster object. na.rm TRUE, default, missing values silently removed. FALSE, missing values removed warning. show.legend logical. layer included legends? NA, default, includes aesthetics mapped. FALSE never includes, TRUE always includes. can also named logical vector finely select aesthetics display. inherit.aes FALSE, overrides default aesthetics, rather combining . interpolate TRUE interpolate linearly, FALSE (default) interpolate. maxcell positive integer. Maximum number cells use plot. use_coltab Logical. applicable SpatRaster objects associated coltab. coltab used plot? See also scale_fill_coltab(). ... arguments passed layer()'s params argument. arguments broadly fall one 4 categories . Notably, arguments position argument, aesthetics required can passed .... Unknown arguments part 4 categories ignored. Static aesthetics mapped scale, fixed value apply layer whole. example, colour = \"red\" linewidth = 3. geom's documentation Aesthetics section lists available options. 'required' aesthetics passed params. Please note passing unmapped aesthetics vectors technically possible, order required length guaranteed parallel input data. constructing layer using stat_*() function, ... argument can used pass parameters geom part layer. example stat_density(geom = \"area\", outline.type = \"\"). geom's documentation lists parameters can accept. Inversely, constructing layer using geom_*() function, ... argument can used pass parameters stat part layer. example geom_area(stat = \"density\", adjust = 0.5). stat's documentation lists parameters can accept. key_glyph argument layer() may also passed .... can one functions described key glyphs, change display layer legend. geom geometric object use display data. Recommended geom SpatRaster \"raster\" (default), \"point\",\"text\" \"label\".","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Visualise SpatRaster objects — geom_spatraster","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Visualise SpatRaster objects — geom_spatraster","text":"terra::plot()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"coords","dir":"Reference","previous_headings":"","what":"Coords","title":"Visualise SpatRaster objects — geom_spatraster","text":"SpatRaster present crs (.e., terra::crs(rast) == \"\") geom make assumption scales. SpatRaster crs, geom uses ggplot2::coord_sf() adjust scales. means also SpatRaster may reprojected.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"aesthetics","dir":"Reference","previous_headings":"","what":"Aesthetics","title":"Visualise SpatRaster objects — geom_spatraster","text":"geom_spatraster() understands following aesthetics: fill alpha fill provided, geom_spatraster() creates ggplot2 layer layers SpatRaster object. Use facet_wrap(~lyr) display properly SpatRaster layers. fill used, contain name one layer present SpatRaster (.e. geom_spatraster(data = rast, aes(fill = )). Names layers can retrieved using names(rast). Using geom_spatraster(..., mapping = aes(fill = NULL)) geom_spatraster(..., fill = ) create layer mapped fill aesthetic. fill can use computed variables. alpha use computed variable. See section Computed variables.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"stat-spatraster-","dir":"Reference","previous_headings":"","what":"stat_spatraster()","title":"Visualise SpatRaster objects — geom_spatraster","text":"stat_spatraster() understands aesthetics geom_spatraster() using geom = \"raster\" (default): fill alpha geom = \"raster\" fill parameter behave geom_spatraster(). another geom used stat_spatraster() understand aesthetics required geom aes(fill = ) applicable. Note also mapping aesthetics x y provided default, user need add aesthetics aes(). cases aesthetics mapped using computed variables. See section Computed variables Examples.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"facets","dir":"Reference","previous_headings":"","what":"Facets","title":"Visualise SpatRaster objects — geom_spatraster","text":"can use facet_wrap(~lyr) creating faceted plot layer SpatRaster object. See ggplot2::facet_wrap() details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"computed-variables","dir":"Reference","previous_headings":"","what":"Computed variables","title":"Visualise SpatRaster objects — geom_spatraster","text":"geom computes internally variables available use aesthetics, using (example) aes(alpha = after_stat(value)) (see ggplot2::after_stat()). after_stat(value): Values SpatRaster. after_stat(lyr): Name layer.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Visualise SpatRaster objects — geom_spatraster","text":"","code":"# \\donttest{ # Avg temperature on spring in Castille and Leon (Spain) file_path <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") library(terra) temp_rast <- rast(file_path) library(ggplot2) # Display a single layer names(temp_rast) #> [1] \"tavg_04\" \"tavg_05\" \"tavg_06\" ggplot() + geom_spatraster(data = temp_rast, aes(fill = tavg_04)) + # You can use coord_sf coord_sf(crs = 3857) + scale_fill_grass_c(palette = \"celsius\") # Display facets ggplot() + geom_spatraster(data = temp_rast) + facet_wrap(~lyr, ncol = 2) + scale_fill_grass_b(palette = \"celsius\", breaks = seq(0, 20, 2.5)) # Non spatial rasters no_crs <- rast(crs = NA, extent = c(0, 100, 0, 100), nlyr = 1) values(no_crs) <- seq_len(ncell(no_crs)) ggplot() + geom_spatraster(data = no_crs) # Downsample ggplot() + geom_spatraster(data = no_crs, maxcell = 25) #> resampled to 32 cells. # } # \\donttest{ # Using stat_spatraster # Default ggplot() + stat_spatraster(data = temp_rast) + facet_wrap(~lyr) # Using points ggplot() + stat_spatraster( data = temp_rast, aes(color = after_stat(value)), geom = \"point\", maxcell = 250 ) + scale_colour_viridis_c(na.value = \"transparent\") + facet_wrap(~lyr) #> resampled to 266 cells. # Using points and labels r_single <- temp_rast %>% select(1) ggplot() + stat_spatraster( data = r_single, aes(color = after_stat(value)), geom = \"point\", maxcell = 2000 ) + stat_spatraster( data = r_single, aes(label = after_stat(round(value, 2))), geom = \"label\", alpha = 0.85, maxcell = 20 ) + scale_colour_viridis_c(na.value = \"transparent\") #> resampled to 2067 cells. #> resampled to 24 cells. # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":null,"dir":"Reference","previous_headings":"","what":"Visualise SpatRaster objects as images — geom_spatraster_rgb","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"geom used visualise SpatRaster objects (see terra::rast()) RGB images. layers combined represent red, green blue channel. plotting SpatRaster objects layer values use geom_spatraster(). underlying implementation based ggplot2::geom_raster().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"","code":"geom_spatraster_rgb( mapping = aes(), data, interpolate = TRUE, r = 1, g = 2, b = 3, alpha = 1, maxcell = 5e+05, max_col_value = 255, ..., stretch = NULL, zlim = NULL )"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"Based layer_spatial() implementation ggspatial package. Thanks Dewey Dunnington ggspatial contributors.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"mapping Ignored. data SpatRaster object. interpolate TRUE interpolate linearly, FALSE (default) interpolate. r, g, b Integer representing number layer data considered red (r), green (g) blue (b) channel. alpha alpha transparency, number [0,1], see argument alpha hsv. maxcell positive integer. Maximum number cells use plot. max_col_value Number giving maximum color values range. 255 (default), result computed efficiently. See grDevices::rgb(). ... arguments passed layer()'s params argument. arguments broadly fall one 4 categories . Notably, arguments position argument, aesthetics required can passed .... Unknown arguments part 4 categories ignored. Static aesthetics mapped scale, fixed value apply layer whole. example, colour = \"red\" linewidth = 3. geom's documentation Aesthetics section lists available options. 'required' aesthetics passed params. Please note passing unmapped aesthetics vectors technically possible, order required length guaranteed parallel input data. constructing layer using stat_*() function, ... argument can used pass parameters geom part layer. example stat_density(geom = \"area\", outline.type = \"\"). geom's documentation lists parameters can accept. Inversely, constructing layer using geom_*() function, ... argument can used pass parameters stat part layer. example geom_area(stat = \"density\", adjust = 0.5). stat's documentation lists parameters can accept. key_glyph argument layer() may also passed .... can one functions described key glyphs, change display layer legend. stretch character. Option stretch values increase contrast: \"lin\" (linear) \"hist\" (histogram). linear stretch uses stretch arguments minq=0.02 maxq=0.98 zlim numeric vector length 2. Range values plot (optional). set, stretch=\"lin\" used, values stretched within range zlim. allows creating consistent coloring SpatRasters different cell-value ranges, even stretching colors improved contrast","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"terra::plotRGB()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"aesthetics","dir":"Reference","previous_headings":"","what":"Aesthetics","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"aes() required. fact, aes() ignored.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"coords","dir":"Reference","previous_headings":"","what":"Coords","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"SpatRaster present crs (.e., terra::crs(rast) == \"\") geom make assumption scales. SpatRaster crs, geom uses ggplot2::coord_sf() adjust scales. means also SpatRaster may reprojected.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"","code":"# \\donttest{ # Tile of Castille and Leon (Spain) from OpenStreetMap file_path <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") library(terra) tile <- rast(file_path) library(ggplot2) ggplot() + geom_spatraster_rgb(data = tile) + # You can use coord_sf coord_sf(crs = 3035) # Combine with sf objects vect_path <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") cyl_sf <- sf::st_read(vect_path) #> Reading layer `cyl' from data source #> `D:\\a\\_temp\\Library\\tidyterra\\extdata\\cyl.gpkg' using driver `GPKG' #> Simple feature collection with 9 features and 3 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: 2892687 ymin: 2017622 xmax: 3341372 ymax: 2361600 #> Projected CRS: ETRS89-extended / LAEA Europe ggplot(cyl_sf) + geom_spatraster_rgb(data = tile) + geom_sf(aes(fill = iso2)) + coord_sf(crs = 3857) + scale_fill_viridis_d(alpha = 0.7) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":null,"dir":"Reference","previous_headings":"","what":"Plot SpatRaster contours — geom_spat_contour","title":"Plot SpatRaster contours — geom_spat_contour","text":"geoms create contours SpatRaster objects. specify valid surface, specify layer aes(z = layer_name), otherwise layers consider creating contours. See also Facets section. underlying implementation based ggplot2::geom_contour(). geom_spatraster_contour_text() creates labeled contours implemented top isoband::isolines_grob().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Plot SpatRaster contours — geom_spat_contour","text":"","code":"geom_spatraster_contour( mapping = NULL, data, ..., maxcell = 5e+05, bins = NULL, binwidth = NULL, breaks = NULL, na.rm = TRUE, show.legend = NA, inherit.aes = TRUE ) geom_spatraster_contour_text( mapping = NULL, data, ..., maxcell = 5e+05, bins = NULL, binwidth = NULL, breaks = NULL, size.unit = \"mm\", label_format = scales::label_number(), label_placer = isoband::label_placer_minmax(), na.rm = TRUE, show.legend = NA, inherit.aes = TRUE ) geom_spatraster_contour_filled( mapping = NULL, data, ..., maxcell = 5e+05, bins = NULL, binwidth = NULL, breaks = NULL, na.rm = TRUE, show.legend = NA, inherit.aes = TRUE )"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Plot SpatRaster contours — geom_spat_contour","text":"mapping Set aesthetic mappings created ggplot2::aes(). See Aesthetics specially use fill aesthetic. data SpatRaster object. ... arguments passed layer()'s params argument. arguments broadly fall one 4 categories . Notably, arguments position argument, aesthetics required can passed .... Unknown arguments part 4 categories ignored. Static aesthetics mapped scale, fixed value apply layer whole. example, colour = \"red\" linewidth = 3. geom's documentation Aesthetics section lists available options. 'required' aesthetics passed params. Please note passing unmapped aesthetics vectors technically possible, order required length guaranteed parallel input data. constructing layer using stat_*() function, ... argument can used pass parameters geom part layer. example stat_density(geom = \"area\", outline.type = \"\"). geom's documentation lists parameters can accept. Inversely, constructing layer using geom_*() function, ... argument can used pass parameters stat part layer. example geom_area(stat = \"density\", adjust = 0.5). stat's documentation lists parameters can accept. key_glyph argument layer() may also passed .... can one functions described key glyphs, change display layer legend. maxcell positive integer. Maximum number cells use plot. bins Number contour bins. Overridden breaks. binwidth width contour bins. Overridden bins. breaks One : Numeric vector set contour breaks function takes range data binwidth input returns breaks output. function can created formula (e.g. ~ fullseq(.x, .y)). Overrides binwidth bins. default, vector length ten pretty() breaks. na.rm TRUE, default, missing values silently removed. FALSE, missing values removed warning. show.legend logical. layer included legends? NA, default, includes aesthetics mapped. FALSE never includes, TRUE always includes. can also named logical vector finely select aesthetics display. inherit.aes FALSE, overrides default aesthetics, rather combining . size.unit size aesthetic interpreted: millimetres (\"mm\", default), points (\"pt\"), centimetres (\"cm\"), inches (\"\"), picas (\"pc\"). label_format One : NULL labels. produced result geom_spatraster_contour(). character vector giving labels (must length breaks produced bins, binwidth, breaks). function takes breaks input returns labels output, default setup (scales::label_number()). label_placer Function controls labels placed along isolines. Uses label_placer_minmax() default.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Plot SpatRaster contours — geom_spat_contour","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Plot SpatRaster contours — geom_spat_contour","text":"terra::contour()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"aesthetics","dir":"Reference","previous_headings":"","what":"Aesthetics","title":"Plot SpatRaster contours — geom_spat_contour","text":"geom_spatraster_contour() / geom_spatraster_contour_text() understands following aesthetics: alpha colour group linetype linewidth geom_spatraster_contour_text() understands also: size label family fontface Additionally, geom_spatraster_contour_filled() understands also following aesthetics, well ones listed : fill subgroup Check ggplot2::geom_contour() info contours vignette(\"ggplot2-specs\", package = \"ggplot2\") overview aesthetics.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"computed-variables","dir":"Reference","previous_headings":"","what":"Computed variables","title":"Plot SpatRaster contours — geom_spat_contour","text":"geom computes internally variables available use aesthetics, using (example) aes(color = after_stat()) (see ggplot2::after_stat()). after_stat(lyr): Name layer. after_stat(level): Height contour. contour lines, numeric vector represents bin boundaries. contour bands, ordered factor represents bin ranges. after_stat(nlevel): Height contour, scaled maximum 1. after_stat(level_low), after_stat(level_high), after_stat(level_mid): (contour bands ) Lower upper bin boundaries band, well mid point boundaries.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"dropped-variables","dir":"Reference","previous_headings":"","what":"Dropped variables","title":"Plot SpatRaster contours — geom_spat_contour","text":"z: contouring, z values individual data points longer available.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"coords","dir":"Reference","previous_headings":"","what":"Coords","title":"Plot SpatRaster contours — geom_spat_contour","text":"SpatRaster present crs (.e., terra::crs(rast) == \"\") geom make assumption scales. SpatRaster crs, geom uses ggplot2::coord_sf() adjust scales. means also SpatRaster may reprojected.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"facets","dir":"Reference","previous_headings":"","what":"Facets","title":"Plot SpatRaster contours — geom_spat_contour","text":"can use facet_wrap(~lyr) creating faceted plot layer SpatRaster object. See ggplot2::facet_wrap() details.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Plot SpatRaster contours — geom_spat_contour","text":"","code":"# \\donttest{ library(terra) # Raster f <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") r <- rast(f) library(ggplot2) ggplot() + geom_spatraster_contour(data = r) # Labelled ggplot() + geom_spatraster_contour_text( data = r, breaks = c(110, 130, 160, 190), color = \"grey10\", family = \"serif\" ) ggplot() + geom_spatraster_contour( data = r, aes(color = after_stat(level)), binwidth = 1, linewidth = 0.4 ) + scale_color_gradientn( colours = hcl.colors(20, \"Inferno\"), guide = guide_coloursteps() ) + theme_minimal() # Filled with breaks ggplot() + geom_spatraster_contour_filled(data = r, breaks = seq(80, 200, 10)) + scale_fill_hypso_d() # Both lines and contours ggplot() + geom_spatraster_contour_filled( data = r, breaks = seq(80, 200, 10), alpha = .7 ) + geom_spatraster_contour( data = r, breaks = seq(80, 200, 2.5), color = \"grey30\", linewidth = 0.1 ) + scale_fill_hypso_d() # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":null,"dir":"Reference","previous_headings":"","what":"Visualise SpatVector objects — ggspatvector","title":"Visualise SpatVector objects — ggspatvector","text":"Wrappers ggplot2::geom_sf() family used visualise SpatVector objects (see terra::vect()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Visualise SpatVector objects — ggspatvector","text":"","code":"geom_spatvector( mapping = aes(), data = NULL, na.rm = FALSE, show.legend = NA, ... ) geom_spatvector_label( mapping = aes(), data = NULL, na.rm = FALSE, show.legend = NA, ..., nudge_x = 0, nudge_y = 0, label.size = 0.25, inherit.aes = TRUE ) geom_spatvector_text( mapping = aes(), data = NULL, na.rm = FALSE, show.legend = NA, ..., nudge_x = 0, nudge_y = 0, check_overlap = FALSE, inherit.aes = TRUE ) stat_spatvector( mapping = NULL, data = NULL, geom = \"rect\", position = \"identity\", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )"},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Visualise SpatVector objects — ggspatvector","text":"mapping Set aesthetic mappings created aes(). specified inherit.aes = TRUE (default), combined default mapping top level plot. must supply mapping plot mapping. data SpatVector object, see terra::vect(). na.rm FALSE, default, missing values removed warning. TRUE, missing values silently removed. show.legend logical. layer included legends? NA, default, includes aesthetics mapped. FALSE never includes, TRUE always includes. can also set one \"polygon\", \"line\", \"point\" override default legend. ... arguments passed ggplot2::geom_sf() functions. often aesthetics, used set aesthetic fixed value, like colour = \"red\" linewidth = 3. nudge_x, nudge_y Horizontal vertical adjustment nudge labels . Useful offsetting text points, particularly discrete scales. jointly specified position. label.size Size label border, mm. inherit.aes FALSE, overrides default aesthetics, rather combining . useful helper functions define data aesthetics inherit behaviour default plot specification, e.g. borders(). check_overlap TRUE, text overlaps previous text layer plotted. check_overlap happens draw time order data. Therefore data arranged label column calling geom_text(). Note argument supported geom_label(). geom geometric object use display data layer. using stat_*() function construct layer, geom argument can used override default coupling stats geoms. geom argument accepts following: Geom ggproto subclass, example GeomPoint. string naming geom. give geom string, strip function name geom_ prefix. example, use geom_point(), give geom \"point\". information ways specify geom, see layer geom documentation. position position adjustment use data layer. can used various ways, including prevent overplotting improving display. position argument accepts following: result calling position function, position_jitter(). method allows passing extra arguments position. string naming position adjustment. give position string, strip function name position_ prefix. example, use position_jitter(), give position \"jitter\". information ways specify position, see layer position documentation.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Visualise SpatVector objects — ggspatvector","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Visualise SpatVector objects — ggspatvector","text":"functions wrappers ggplot2::geom_sf() functions. Since fortify.SpatVector() method provided, ggplot2 treat SpatVector way sf object. side effect can use ggplot2::geom_sf() directly SpatVector objects. See ggplot2::geom_sf() details aesthetics, etc.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Visualise SpatVector objects — ggspatvector","text":"terra::plot()","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Visualise SpatVector objects — ggspatvector","text":"","code":"# \\donttest{ # Create a SpatVector extfile <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") cyl <- terra::vect(extfile) class(cyl) #> [1] \"SpatVector\" #> attr(,\"package\") #> [1] \"terra\" library(ggplot2) ggplot(cyl) + geom_spatvector() # With params ggplot(cyl) + geom_spatvector(aes(fill = name), color = NA) + scale_fill_viridis_d() + coord_sf(crs = 3857) # Add labels ggplot(cyl) + geom_spatvector(aes(fill = name), color = NA) + geom_spatvector_text(aes(label = iso2), fontface = \"bold\", color = \"red\" ) + scale_fill_viridis_d(alpha = 0.4) + coord_sf(crs = 3857) # You can use now geom_sf with SpatVectors! ggplot(cyl) + geom_sf() + labs( title = paste(\"cyl is\", as.character(class(cyl))), subtitle = \"With geom_sf()\" ) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Get a nice glimpse of your Spat* objects — glimpse.Spat","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"glimpse() like transposed version print(): layers/columns run page, data runs across. makes possible see every layer/column Spat* object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"","code":"# S3 method for class 'SpatRaster' glimpse(x, width = NULL, ..., n = 10, max_extra_cols = 20) # S3 method for class 'SpatVector' glimpse(x, width = NULL, ..., n = 10, max_extra_cols = 20)"},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"x SpatRaster created terra::rast() SpatVector created terra::vect(). width Width output: defaults setting width option (finite) width console. See dplyr::glimpse(). ... Arguments passed as_tibble() methods SpatRaster SpatVector. See as_tibble.SpatRaster(). n Maximum number rows show. max_extra_cols Number extra columns layers print abbreviated information , n small Spat* object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"original x (invisibly) returned, allowing glimpse() used within data pipeline.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"print()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"Implementation generic dplyr::glimpse() function Spat*. objects.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"","code":"library(terra) # SpatVector v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) v %>% glimpse(n = 2) #> # A SpatVector 9 x 3 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\", \"ES… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> # ℹ 1 more variable : name #> # ℹ Use `tidyterra::glimpse(n = ...)` to see more columns # Use on a pipeline v %>% glimpse() %>% mutate(a = 30) %>% # with options glimpse(geom = \"WKT\") #> # A SpatVector 9 x 3 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\", \"ES… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia\", \"S… #> # A SpatVector 9 x 4 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\",… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia\"… #> $ a 30, 30, 30, 30, 30, 30, 30, 30, 30 #> $ geometry \"POLYGON ((3126360.2417 2066777.7545, 3125073.9752 2065007.29… # SpatRaster r <- rast(system.file(\"extdata/cyl_elev.tif\", package = \"tidyterra\")) r %>% glimpse() #> # A SpatRaster 126 x 212 x 1 layer (26,712 cells) #> # Resolution (x / y): (1' 30\" , 1' 30\") #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([7° 4' 30\" W / 1° 46' 30\" W] , [40° 4' 60\" N / 43° 13' 60\" N]) #> #> $ elevation_m 700.2969, 780.3889, 706.1250, 568.9722, 584.9028, 506.7361… # Use on a pipeline r %>% glimpse() %>% mutate(b = elevation_m / 100) %>% # With options glimpse(xy = TRUE) #> # A SpatRaster 126 x 212 x 1 layer (26,712 cells) #> # Resolution (x / y): (1' 30\" , 1' 30\") #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([7° 4' 30\" W / 1° 46' 30\" W] , [40° 4' 60\" N / 43° 13' 60\" N]) #> #> $ elevation_m 700.2969, 780.3889, 706.1250, 568.9722, 584.9028, 506.7361… #> # A SpatRaster 126 x 212 x 2 layers (26,712 cells) #> # Resolution (x / y): (1' 30\" , 1' 30\") #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([7° 4' 30\" W / 1° 46' 30\" W] , [40° 4' 60\" N / 43° 13' 60\" N]) #> #> $ elevation_m 700.2969, 780.3889, 706.1250, 568.9722, 584.9028, 506.7361… #> $ b 7.002969, 7.803889, 7.061250, 5.689722, 5.849028, 5.067361…"},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":null,"dir":"Reference","previous_headings":"","what":"GRASS color tables — grass_db","title":"GRASS color tables — grass_db","text":"tibble including color map 51 gradient palettes. palettes includes also definition colors limits can used ggplot2::scale_fill_gradientn().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"GRASS color tables — grass_db","text":"tibble 2920 rows 6 columns. following fields: pal Name palette. limit (Optional) limit color. r Value red channel (RGB color mode). g Value green channel (RGB color mode). b Value blue channel (RGB color mode). hex Hex code color.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"GRASS color tables — grass_db","text":"Derived https://github.com/OSGeo/grass/tree/main/lib/gis/colors. See also r.color - GRASS GIS Manual.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"GRASS color tables — grass_db","text":"Summary palettes provided, description recommended use:","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"GRASS color tables — grass_db","text":"terra::map.pal()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"GRASS color tables — grass_db","text":"GRASS Development Team (2024). Geographic Resources Analysis Support System (GRASS) Software, Version 8.3.2. Open Source Geospatial Foundation, USA. https://grass.osgeo.org.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"GRASS color tables — grass_db","text":"","code":"# \\donttest{ data(\"grass_db\") grass_db #> # A tibble: 2,920 × 6 #> pal limit r g b hex #> #> 1 aspect NA 0 0 0 #000000 #> 2 aspect NA 255 255 255 #FFFFFF #> 3 aspect NA 0 0 0 #000000 #> 4 aspectcolr 0 255 255 255 #FFFFFF #> 5 aspectcolr 1 255 255 0 #FFFF00 #> 6 aspectcolr 90 0 255 0 #00FF00 #> 7 aspectcolr 180 0 255 255 #00FFFF #> 8 aspectcolr 270 255 0 0 #FF0000 #> 9 aspectcolr 360 255 255 0 #FFFF00 #> 10 bcyr NA 0 0 255 #0000FF #> # ℹ 2,910 more rows # Select a palette srtm_plus <- grass_db %>% filter(pal == \"srtm_plus\") f <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") r <- terra::rast(f) library(ggplot2) p <- ggplot() + geom_spatraster(data = r) + labs(fill = \"elevation\") p + scale_fill_gradientn(colors = srtm_plus$hex) # Use with limits p + scale_fill_gradientn( colors = srtm_plus$hex, values = scales::rescale(srtm_plus$limit), limit = range(srtm_plus$limit), na.value = \"lightblue\" ) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Group a SpatVector by one or more variables — group-by.SpatVector","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"data operations done groups defined variables. group_by.SpatVector() adds new attributes existing SpatVector indicating corresponding groups. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"","code":"# S3 method for class 'SpatVector' group_by(.data, ..., .add = FALSE, .drop = group_by_drop_default(.data)) # S3 method for class 'SpatVector' ungroup(x, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":".data, x SpatVector object. See Methods. ... group_by(), variables computations group . Computations always done ungrouped data frame. perform computations grouped data, need use separate mutate() step group_by(). Computations allowed nest_by(). ungroup(), variables remove grouping. .add FALSE, default, group_by() override existing groups. add existing groups, use .add = TRUE. argument previously called add, prevented creating new grouping variable called add, conflicts naming conventions. .drop Drop groups formed factor levels appear data? default TRUE except .data previously grouped .drop = FALSE. See group_by_drop_default() details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"SpatVector object additional attribute.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"See Details dplyr::group_by().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"Implementation generic dplyr::group_by() family functions SpatVector objects. mixing terra dplyr syntax grouped SpatVector (.e, subsetting SpatVector like v[1:3,1:2]) groups attribute can corrupted. tidyterra try re-group SpatVector. triggered next time use dplyr verb SpatVector. Note also operations (terra::spatSample()) create new SpatVector. cases, result preserve groups attribute. Use group_by() re-group.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"","code":"# \\donttest{ library(terra) f <- system.file(\"ex/lux.shp\", package = \"terra\") p <- vect(f) by_name1 <- p %>% group_by(NAME_1) # grouping doesn't change how the SpatVector looks by_name1 #> class : SpatVector #> geometry : polygons #> dimensions : 12, 6 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> source : lux.shp #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : ID_1 NAME_1 ID_2 NAME_2 AREA POP #> type : #> values : 1 Diekirch 1 Clervaux 312 1.808e+04 #> 1 Diekirch 2 Diekirch 218 3.254e+04 #> 1 Diekirch 3 Redange 259 1.866e+04 # But add metadata for grouping: See the coercion to tibble # Not grouped p_tbl <- as_tibble(p) class(p_tbl) #> [1] \"tbl_df\" \"tbl\" \"data.frame\" head(p_tbl, 3) #> # A tibble: 3 × 6 #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 Diekirch 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 Diekirch 3 Redange 259 18664 # Grouped by_name1_tbl <- as_tibble(by_name1) class(by_name1_tbl) #> [1] \"grouped_df\" \"tbl_df\" \"tbl\" \"data.frame\" head(by_name1_tbl, 3) #> # A tibble: 3 × 6 #> # Groups: NAME_1 [1] #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 Diekirch 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 Diekirch 3 Redange 259 18664 # It changes how it acts with the other dplyr verbs: by_name1 %>% summarise( pop = mean(POP), area = sum(AREA) ) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 3 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_1 pop area #> type : #> values : Diekirch 1.824e+04 1128 #> Grevenmacher 2.37e+04 527 #> Luxembourg 1.099e+05 906 # Each call to summarise() removes a layer of grouping by_name2_name1 <- p %>% group_by(NAME_2, NAME_1) by_name2_name1 #> class : SpatVector #> geometry : polygons #> dimensions : 12, 6 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> source : lux.shp #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : ID_1 NAME_1 ID_2 NAME_2 AREA POP #> type : #> values : 1 Diekirch 1 Clervaux 312 1.808e+04 #> 1 Diekirch 2 Diekirch 218 3.254e+04 #> 1 Diekirch 3 Redange 259 1.866e+04 group_data(by_name2_name1) #> # A tibble: 12 × 3 #> NAME_2 NAME_1 .rows #> > #> 1 Capellen Luxembourg [1] #> 2 Clervaux Diekirch [1] #> 3 Diekirch Diekirch [1] #> 4 Echternach Grevenmacher [1] #> 5 Esch-sur-Alzette Luxembourg [1] #> 6 Grevenmacher Grevenmacher [1] #> 7 Luxembourg Luxembourg [1] #> 8 Mersch Luxembourg [1] #> 9 Redange Diekirch [1] #> 10 Remich Grevenmacher [1] #> 11 Vianden Diekirch [1] #> 12 Wiltz Diekirch [1] by_name2 <- by_name2_name1 %>% summarise(n = dplyr::n()) by_name2 #> class : SpatVector #> geometry : polygons #> dimensions : 12, 3 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_2 NAME_1 n #> type : #> values : Capellen Luxembourg 1 #> Clervaux Diekirch 1 #> Diekirch Diekirch 1 group_data(by_name2) #> # A tibble: 12 × 2 #> NAME_2 .rows #> > #> 1 Capellen [1] #> 2 Clervaux [1] #> 3 Diekirch [1] #> 4 Echternach [1] #> 5 Esch-sur-Alzette [1] #> 6 Grevenmacher [1] #> 7 Luxembourg [1] #> 8 Mersch [1] #> 9 Redange [1] #> 10 Remich [1] #> 11 Vianden [1] #> 12 Wiltz [1] # To removing grouping, use ungroup by_name2 %>% ungroup() %>% summarise(n = sum(n)) #> class : SpatVector #> geometry : polygons #> dimensions : 1, 1 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : n #> type : #> values : 12 # By default, group_by() overrides existing grouping by_name2_name1 %>% group_by(ID_1, ID_2) %>% group_vars() #> [1] \"ID_1\" \"ID_2\" # Use add = TRUE to instead append by_name2_name1 %>% group_by(ID_1, ID_2, .add = TRUE) %>% group_vars() #> [1] \"NAME_2\" \"NAME_1\" \"ID_1\" \"ID_2\" # You can group by expressions: this is a short-hand # for a mutate() followed by a group_by() p %>% group_by(ID_COMB = ID_1 * 100 / ID_2) %>% relocate(ID_COMB, .before = 1) #> class : SpatVector #> geometry : polygons #> dimensions : 12, 7 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> source : lux.shp #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : ID_COMB ID_1 NAME_1 ID_2 NAME_2 AREA POP #> type : #> values : 100 1 Diekirch 1 Clervaux 312 1.808e+04 #> 50 1 Diekirch 2 Diekirch 218 3.254e+04 #> 33.33 1 Diekirch 3 Redange 259 1.866e+04 # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/group_data.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Grouping metadata for SpatVector objects — group_data.SpatVector","title":"Grouping metadata for SpatVector objects — group_data.SpatVector","text":"collection functions accesses data grouped SpatVector objects various ways: group_data() returns tibble defines grouping structure. columns give values grouping variables. last column, always called .rows, list integer vectors gives location rows group. group_keys() returns tibble describing groups. group_rows() returns list integer vectors giving rows group contains. group_indices() returns integer vector length .data gives group row belongs . group_vars() gives names grouping variables character vector. groups() gives names grouping variables list symbols. group_size() gives size group. n_groups() gives total number groups. See dplyr::group_data().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group_data.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Grouping metadata for SpatVector objects — group_data.SpatVector","text":"","code":"# S3 method for class 'SpatVector' group_data(.data) # S3 method for class 'SpatVector' group_keys(.tbl, ...) # S3 method for class 'SpatVector' group_indices(.data, ...) # S3 method for class 'SpatVector' group_vars(x) # S3 method for class 'SpatVector' groups(x) # S3 method for class 'SpatVector' group_size(x) # S3 method for class 'SpatVector' n_groups(x)"},{"path":"https://dieghernan.github.io/tidyterra/reference/group_data.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Grouping metadata for SpatVector objects — group_data.SpatVector","text":".data, .tbl, x SpatVector. ... Use ... now deprecated; please use group_by() first instead.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group_data.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Grouping metadata for SpatVector objects — group_data.SpatVector","text":"See description function. results usually tibbles, lists vectors. functions return SpatVector objects.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group_data.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Grouping metadata for SpatVector objects — group_data.SpatVector","text":"","code":"library(terra) v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) v$gr_1 <- rep_len(c(\"A\", \"A\", \"B\"), length.out = nrow(v)) v$gr_2 <- rep_len(c(\"C\", \"D\"), length.out = nrow(v)) # Ungrouped n_groups(v) #> [1] 1 group_vars(v) #> character(0) group_keys(v) #> # A tibble: 1 × 0 group_size(v) #> [1] 9 groups(v) #> list() group_rows(v) #> [1]> #> [[1]] #> [1] 1 2 3 4 5 6 7 8 9 #> group_data(v) #> # A tibble: 1 × 1 #> .rows #> > #> 1 [9] group_indices(v) #> [1] 1 1 1 1 1 1 1 1 1 # Grouped by one var gv <- group_by(v, gr_1) n_groups(gv) #> [1] 2 group_vars(gv) #> [1] \"gr_1\" group_keys(gv) #> # A tibble: 2 × 1 #> gr_1 #> #> 1 A #> 2 B group_size(gv) #> [1] 6 3 groups(gv) #> [[1]] #> gr_1 #> group_rows(gv) #> [2]> #> [[1]] #> [1] 1 2 4 5 7 8 #> #> [[2]] #> [1] 3 6 9 #> group_data(gv) #> # A tibble: 2 × 2 #> gr_1 .rows #> > #> 1 A [6] #> 2 B [3] group_indices(gv) #> [1] 1 1 2 1 1 2 1 1 2 # Grouped by several vars gv2 <- group_by(v, gr_1, gr_2) n_groups(gv2) #> [1] 4 group_vars(gv2) #> [1] \"gr_1\" \"gr_2\" group_keys(gv2) #> # A tibble: 4 × 2 #> gr_1 gr_2 #> #> 1 A C #> 2 A D #> 3 B C #> 4 B D group_size(gv2) #> [1] 3 3 2 1 groups(gv2) #> [[1]] #> gr_1 #> #> [[2]] #> gr_2 #> group_rows(gv2) #> [4]> #> [[1]] #> [1] 1 5 7 #> #> [[2]] #> [1] 2 4 8 #> #> [[3]] #> [1] 3 9 #> #> [[4]] #> [1] 6 #> group_data(gv2) #> # A tibble: 4 × 3 #> gr_1 gr_2 .rows #> > #> 1 A C [3] #> 2 A D [3] #> 3 B C [2] #> 4 B D [1] group_indices(gv2) #> [1] 1 2 3 2 1 4 1 2 3"},{"path":"https://dieghernan.github.io/tidyterra/reference/hypsometric_tints_db.html","id":null,"dir":"Reference","previous_headings":"","what":"Hypsometric palettes database — hypsometric_tints_db","title":"Hypsometric palettes database — hypsometric_tints_db","text":"tibble including color map 33 gradient palettes. palettes includes also definition colors limits terms elevation (meters), can used ggplot2::scale_fill_gradientn().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/hypsometric_tints_db.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Hypsometric palettes database — hypsometric_tints_db","text":"tibble 1102 rows 6 columns. following fields: pal Name palette. limit Recommended elevation limit (meters) color. r Value red channel (RGB color mode). g Value green channel (RGB color mode). b Value blue channel (RGB color mode). hex Hex code color.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/hypsometric_tints_db.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Hypsometric palettes database — hypsometric_tints_db","text":"cpt-city: http://seaviewsensing.com/pub/cpt-city/.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/hypsometric_tints_db.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Hypsometric palettes database — hypsometric_tints_db","text":"","code":"# \\donttest{ data(\"hypsometric_tints_db\") hypsometric_tints_db #> # A tibble: 1,102 × 6 #> pal limit r g b hex #> #> 1 arctic -5000 44 53 99 #2C3563 #> 2 arctic -4900 46 54 100 #2E3664 #> 3 arctic -4800 48 56 103 #303867 #> 4 arctic -4700 50 59 106 #323B6A #> 5 arctic -4600 52 60 107 #343C6B #> 6 arctic -4500 54 61 109 #363D6D #> 7 arctic -4400 56 63 111 #383F6F #> 8 arctic -4300 57 65 113 #394171 #> 9 arctic -4200 60 68 116 #3C4474 #> 10 arctic -4100 62 70 118 #3E4676 #> # ℹ 1,092 more rows # Select a palette wikicols <- hypsometric_tints_db %>% filter(pal == \"wiki-2.0\") f <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") r <- terra::rast(f) library(ggplot2) p <- ggplot() + geom_spatraster(data = r) + labs(fill = \"elevation\") p + scale_fill_gradientn(colors = wikicols$hex) # Use with limits p + scale_fill_gradientn( colors = wikicols$hex, values = scales::rescale(wikicols$limit), limit = range(wikicols$limit) ) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/is_grouped_spatvector.html","id":null,"dir":"Reference","previous_headings":"","what":"A grouped SpatVector — is_grouped_spatvector","title":"A grouped SpatVector — is_grouped_spatvector","text":"easiest way create grouped SpatVector call group_by() method SpatVector: take care capturing unevaluated expressions . See group_by.SpatVector() details. function adapted version dplyr::is_grouped_df(). See also group_data.SpatVector() accessory functions retrieve various metadata grouped SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/is_grouped_spatvector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"A grouped SpatVector — is_grouped_spatvector","text":"","code":"is_grouped_spatvector(x)"},{"path":"https://dieghernan.github.io/tidyterra/reference/is_grouped_spatvector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"A grouped SpatVector — is_grouped_spatvector","text":"x SpatVector.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/is_regular_grid.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if x and y positions conforms a regular grid — is_regular_grid","title":"Check if x and y positions conforms a regular grid — is_regular_grid","text":"Assess coordinates x,y object conforms regular grid. function called side effects. function internally called as_spatraster().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/is_regular_grid.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if x and y positions conforms a regular grid — is_regular_grid","text":"","code":"is_regular_grid(xy, digits = 6)"},{"path":"https://dieghernan.github.io/tidyterra/reference/is_regular_grid.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if x and y positions conforms a regular grid — is_regular_grid","text":"xy matrix, data frame tibble least two columns representing x y coordinates. digits integer set precision detecting whether points regular grid (low number digits low precision).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/is_regular_grid.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check if x and y positions conforms a regular grid — is_regular_grid","text":"invisible() regular error message otherwise","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/is_regular_grid.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check if x and y positions conforms a regular grid — is_regular_grid","text":"","code":"p <- matrix(1:90, nrow = 45, ncol = 2) is_regular_grid(p) # Jitter location set.seed(1234) jitter <- runif(length(p)) / 10e4 p_jitter <- p + jitter # Need to adjust digits is_regular_grid(p_jitter, digits = 4)"},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"Mutating joins add columns y x, matching observations based keys. four mutating joins: inner join, three outer joins. See dplyr::inner_join() details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"","code":"# S3 method for class 'SpatVector' inner_join( x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = NULL ) # S3 method for class 'SpatVector' left_join( x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = NULL ) # S3 method for class 'SpatVector' right_join( x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = NULL ) # S3 method for class 'SpatVector' full_join( x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = NULL )"},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"x SpatVector created terra::vect(). y data frame object coercible data frame. SpatVector sf object provided return error (see terra::intersect() performing spatial joins). join specification created join_by(), character vector variables join . NULL, default, *_join() perform natural join, using variables common across x y. message lists variables can check correct; suppress message supplying explicitly. join different variables x y, use join_by() specification. example, join_by(== b) match x$y$b. join multiple variables, use join_by() specification multiple expressions. example, join_by(== b, c == d) match x$y$b x$c y$d. column names x y, can shorten listing variable names, like join_by(, c). join_by() can also used perform inequality, rolling, overlap joins. See documentation ?join_by details types joins. simple equality joins, can alternatively specify character vector variable names join . example, = c(\"\", \"b\") joins x$y$x$b y$b. variable names differ x y, use named character vector like = c(\"x_a\" = \"y_a\", \"x_b\" = \"y_b\"). perform cross-join, generating combinations x y, see cross_join(). copy x y data source, copy TRUE, y copied src x. allows join tables across srcs, potentially expensive operation must opt . suffix non-joined duplicate variables x y, suffixes added output disambiguate . character vector length 2. ... parameters passed onto methods. keep join keys x y preserved output? NULL, default, joins equality retain keys x, joins inequality retain keys inputs. TRUE, keys inputs retained. FALSE, keys x retained. right full joins, data key columns corresponding rows exist y merged key columns x. used joining inequality conditions.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"terra::merge()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"Implementation generic dplyr::inner_join() family","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"geometry column sticky behavior. means result always geometry x records matches join conditions. Note right_join() full_join() possible return empty geometries (since y expected data frame geometries). Although kind joining operations may common spatial manipulation, possible function crashes, since handling EMPTY geometries differs terra sf.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"","code":"library(terra) library(ggplot2) # Vector v <- terra::vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) # A data frame df <- data.frame( cpro = sprintf(\"%02d\", 1:10), x = runif(10), y = runif(10), letter = rep_len(LETTERS[1:3], length.out = 10) ) # Inner join inner <- v %>% inner_join(df) #> Joining with `by = join_by(cpro)` nrow(inner) #> [1] 2 autoplot(inner, aes(fill = letter)) + ggtitle(\"Inner Join\") # Left join left <- v %>% left_join(df) #> Joining with `by = join_by(cpro)` nrow(left) #> [1] 9 autoplot(left, aes(fill = letter)) + ggtitle(\"Left Join\") # \\donttest{ # Right join right <- v %>% right_join(df) #> Joining with `by = join_by(cpro)` nrow(right) #> [1] 10 autoplot(right, aes(fill = letter)) + ggtitle(\"Right Join\") # There are empty geometries, check with data from df ggplot(right, aes(x, y)) + geom_point(aes(color = letter)) # Full join full <- v %>% full_join(df) #> Joining with `by = join_by(cpro)` nrow(full) #> [1] 17 autoplot(full, aes(fill = letter)) + ggtitle(\"Full Join\") # Check with data from df ggplot(full, aes(x, y)) + geom_point(aes(color = letter)) #> Warning: Removed 7 rows containing missing values or values outside the scale range #> (`geom_point()`). # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"mutate() adds new layers/attributes preserves existing ones Spat* object. transmute() adds new layers/attributes drops existing ones. New variables overwrite existing variables name. Variables can removed setting value NULL.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"","code":"# S3 method for class 'SpatRaster' mutate(.data, ...) # S3 method for class 'SpatVector' mutate(.data, ...) # S3 method for class 'SpatRaster' transmute(.data, ...) # S3 method for class 'SpatVector' transmute(.data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... Name-value pairs. name gives name layer/attribute output.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"terra methods modifying cell values: terra::ifel(), terra::classify(), terra::clamp(), terra::app(), terra::lapp(), terra::tapp()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"Implementation generic dplyr::mutate(), dplyr::transmute() functions.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"Add new layers preserves existing ones. result SpatRaster extent, resolution crs .data. values (possibly number) layers modified. transmute() keep layers created ....","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"result SpatVector modified (possibly renamed) attributes function call. transmute() keep attributes created ....","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"","code":"library(terra) # SpatRaster method f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") spatrast <- rast(f) mod <- spatrast %>% mutate(exp_lyr1 = exp(tavg_04 / 10)) %>% select(tavg_04, exp_lyr1) mod #> class : SpatRaster #> dimensions : 87, 118, 2 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source(s) : memory #> names : tavg_04, exp_lyr1 #> min values : 1.885463, 1.207493 #> max values : 13.283829, 3.774934 plot(mod) # SpatVector method f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- vect(f) v %>% mutate(cpro2 = paste0(cpro, \"-CyL\")) %>% select(cpro, cpro2) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 2 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro cpro2 #> type : #> values : 05 05-CyL #> 09 09-CyL #> 24 24-CyL"},{"path":"https://dieghernan.github.io/tidyterra/reference/pipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Pipe operator — %>%","title":"Pipe operator — %>%","text":"See magrittr::%>% details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pipe operator — %>%","text":"","code":"lhs %>% rhs"},{"path":"https://dieghernan.github.io/tidyterra/reference/pipe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pipe operator — %>%","text":"lhs value magrittr placeholder. rhs function call using magrittr semantics.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pipe operator — %>%","text":"result calling rhs(lhs).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"pivot_longer() \"lengthens\" data, increasing number rows decreasing number columns. inverse transformation pivot_wider.SpatVector() Learn tidyr::pivot_wider().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"","code":"# S3 method for class 'SpatVector' pivot_longer( data, cols, ..., cols_vary = \"fastest\", names_to = \"name\", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, names_transform = NULL, names_repair = \"check_unique\", values_to = \"value\", values_drop_na = FALSE, values_ptypes = NULL, values_transform = NULL )"},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"data SpatVector pivot. cols Columns pivot longer format. ... Additional arguments passed methods. cols_vary pivoting cols longer format, output rows arranged relative original row number? \"fastest\", default, keeps individual rows cols close together output. often produces intuitively ordered output least one key column data involved pivoting process. \"slowest\" keeps individual columns cols close together output. often produces intuitively ordered output utilize columns data pivoting process. names_to character vector specifying new column columns create information stored column names data specified cols. length 0, NULL supplied, columns created. length 1, single column created contain column names specified cols. length >1, multiple columns created. case, one names_sep names_pattern must supplied specify column names split. also two additional character values can take advantage : NA discard corresponding component column name. \".value\" indicates corresponding component column name defines name output column containing cell values, overriding values_to entirely. names_prefix regular expression used remove matching text start variable name. names_sep, names_pattern names_to contains multiple values, arguments control column name broken . names_sep takes specification separate(), can either numeric vector (specifying positions break ), single string (specifying regular expression split ). names_pattern takes specification extract(), regular expression containing matching groups (()). arguments give enough control, use pivot_longer_spec() create spec object process manually needed. names_ptypes, values_ptypes Optionally, list column name-prototype pairs. Alternatively, single empty prototype can supplied, applied columns. prototype (ptype short) zero-length vector (like integer() numeric()) defines type, class, attributes vector. Use arguments want confirm created columns types expect. Note want change (instead confirm) types specific columns, use names_transform values_transform instead. names_transform, values_transform Optionally, list column name-function pairs. Alternatively, single function can supplied, applied columns. Use arguments need change types specific columns. example, names_transform = list(week = .integer) convert character variable called week integer. specified, type columns generated names_to character, type variables generated values_to common type input columns used generate . names_repair happens output invalid column names? default, \"check_unique\" error columns duplicated. Use \"minimal\" allow duplicates output, \"unique\" de-duplicated adding numeric suffixes. See vctrs::vec_as_names() options. values_to string specifying name column create data stored cell values. names_to character containing special .value sentinel, value ignored, name value column derived part existing column names. values_drop_na TRUE, drop rows contain NAs value_to column. effectively converts explicit missing values implicit missing values, generally used missing values data created structure.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"Implementation generic tidyr::pivot_longer() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"geometry column sticky behavior. means result always geometry data.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"","code":"# \\donttest{ library(dplyr) library(tidyr) #> #> Attaching package: 'tidyr' #> The following object is masked from 'package:terra': #> #> extract library(ggplot2) library(terra) temp <- rast((system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\"))) cyl <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) %>% project(temp) # Add average temp temps <- terra::extract(temp, cyl, fun = \"mean\", na.rm = TRUE, xy = TRUE) cyl_temp <- cbind(cyl, temps) %>% glimpse() #> # A SpatVector 9 x 7 #> # Geometry type: Polygons #> # Projected CRS: World_Robinson #> # CRS projection units: meter #> # Extent (x / y) : ([ -607,946.2 / -153,819.7] , [4,285,436.1 / 4,619,242.7]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\", … #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia\",… #> $ ID 1, 2, 3, 4, 5, 6, 7, 8, 9 #> $ tavg_04 8.098067, 8.405818, 7.566549, 8.558559, 9.593332, 8.727293, 7.… #> $ tavg_05 11.84584, 12.07354, 11.09056, 12.11431, 13.00844, 12.35747, 11… #> $ tavg_06 16.64684, 16.14488, 15.51468, 16.45461, 17.55421, 17.05671, 16… # And pivot long for plot cyl_temp %>% pivot_longer( cols = tavg_04:tavg_06, names_to = \"label\", values_to = \"temp\" ) %>% ggplot() + geom_spatvector(aes(fill = temp)) + facet_wrap(~label, ncol = 1) + scale_fill_whitebox_c(palette = \"muted\") # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"pivot_wider() \"widens\" SpatVector, increasing number columns decreasing number rows. inverse transformation pivot_longer.SpatVector().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"","code":"# S3 method for class 'SpatVector' pivot_wider( data, ..., id_cols = NULL, id_expand = FALSE, names_from = \"name\", names_prefix = \"\", names_sep = \"_\", names_glue = NULL, names_sort = FALSE, names_vary = \"fastest\", names_expand = FALSE, names_repair = \"check_unique\", values_from = \"value\", values_fill = NULL, values_fn = NULL, unused_fn = NULL )"},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"data SpatVector pivot. ... Additional arguments passed methods. id_cols set columns uniquely identify observation. Typically used redundant variables, .e. variables whose values perfectly correlated existing variables. Defaults columns data except columns specified names_from values_from. tidyselect expression supplied, evaluated data removing columns specified names_from values_from. Note \"geometry\" columns sticky, hence removed names_from values_from. id_expand values id_cols columns expanded expand() pivoting? results rows, output contain complete expansion possible values id_cols. Implicit factor levels represented data become explicit. Additionally, row values corresponding expanded id_cols sorted. names_from, values_from pair arguments describing column (columns) get name output column (names_from), column (columns) get cell values (values_from). values_from contains multiple values, value added front output column. names_prefix regular expression used remove matching text start variable name. names_sep names_from values_from contains multiple variables, used join values together single string use column name. names_glue Instead names_sep names_prefix, can supply glue specification uses names_from columns (special .value) create custom column names. names_sort column names sorted? FALSE, default, column names ordered first appearance. names_vary names_from identifies column (columns) multiple unique values, multiple values_from columns provided, order resulting column names combined? \"fastest\" varies names_from values fastest, resulting column naming scheme form: value1_name1, value1_name2, value2_name1, value2_name2. default. \"slowest\" varies names_from values slowest, resulting column naming scheme form: value1_name1, value2_name1, value1_name2, value2_name2. names_expand values names_from columns expanded expand() pivoting? results columns, output contain column names corresponding complete expansion possible values names_from. Implicit factor levels represented data become explicit. Additionally, column names sorted, identical names_sort produce. names_repair happens output invalid column names? default, \"check_unique\" error columns duplicated. Use \"minimal\" allow duplicates output, \"unique\" de-duplicated adding numeric suffixes. See vctrs::vec_as_names() options. values_fill Optionally, (scalar) value specifies value filled missing. can named list want apply different fill values different value columns. values_fn Optionally, function applied value cell output. typically use combination id_cols names_from columns uniquely identify observation. can named list want apply different aggregations different values_from columns. unused_fn Optionally, function applied summarize values unused columns (.e. columns identified id_cols, names_from, values_from). default drops unused columns result. can named list want apply different aggregations different unused columns. id_cols must supplied unused_fn useful, since otherwise unspecified columns considered id_cols. similar grouping id_cols summarizing unused columns using unused_fn.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"Implementation generic tidyr::pivot_wider() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"geometry column sticky behavior. means result always geometry data.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"","code":"# \\donttest{ library(dplyr) library(tidyr) library(ggplot2) cyl <- terra::vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) # Add extra row with info xtra <- cyl %>% slice(c(2, 3)) %>% mutate( label = \"extra\", value = TRUE ) %>% rbind(cyl, .) %>% glimpse() #> # A SpatVector 11 x 5 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\", \"E… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\", \"09\", \"24\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia\", \"… #> $ label NA, NA, NA, NA, NA, NA, NA, NA, NA, \"extra\", \"extra\" #> $ value NA, NA, NA, NA, NA, NA, NA, NA, NA, TRUE, TRUE # Pivot by geom xtra %>% pivot_wider( id_cols = iso2:name, values_from = value, names_from = label ) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 5 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name NA extra #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos TRUE #> ES-LE 24 Leon TRUE # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/princess_db.html","id":null,"dir":"Reference","previous_headings":"","what":"Princess palettes database — princess_db","title":"Princess palettes database — princess_db","text":"tibble including color map 15 gradient palettes.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/princess_db.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Princess palettes database — princess_db","text":"tibble 75 rows 5 columns. following fields: pal Name palette. r Value red channel (RGB color mode). g Value green channel (RGB color mode). b Value blue channel (RGB color mode). hex Hex code color.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/princess_db.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Princess palettes database — princess_db","text":"https://leahsmyth.github.io/Princess-Colour-Schemes/index.html.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/princess_db.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Princess palettes database — princess_db","text":"","code":"# \\donttest{ data(\"princess_db\") princess_db #> # A tibble: 75 × 5 #> pal r g b hex #> #> 1 snow 227 75 98 #e34b62 #> 2 snow 138 192 229 #8ac0e5 #> 3 snow 10 100 165 #0a64a5 #> 4 snow 255 235 148 #ffeb94 #> 5 snow 255 202 53 #ffca35 #> 6 ella 215 234 246 #d7eaf6 #> 7 ella 177 222 245 #b1def5 #> 8 ella 140 197 232 #8cc5e8 #> 9 ella 59 139 189 #3b8bbd #> 10 ella 40 98 135 #286287 #> # ℹ 65 more rows # Select a palette maori <- princess_db %>% filter(pal == \"maori\") f <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") r <- terra::rast(f) library(ggplot2) p <- ggplot() + geom_spatraster(data = r) + labs(fill = \"elevation\") p + scale_fill_gradientn(colors = maori$hex) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract a single layer/attribute — pull.Spat","title":"Extract a single layer/attribute — pull.Spat","text":"pull() similar $ data frame. mostly useful looks little nicer pipes can optionally name output. possible extract geographic coordinates SpatRaster. need use pull(.data, x, xy = TRUE). x y reserved names terra, since refer geographic coordinates layer. See Examples section layer names as_tibble.Spat().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract a single layer/attribute — pull.Spat","text":"","code":"# S3 method for class 'SpatRaster' pull(.data, var = -1, name = NULL, ...) # S3 method for class 'SpatVector' pull(.data, var = -1, name = NULL, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract a single layer/attribute — pull.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). var variable specified : literal layer/attribute name. positive integer, giving position counting left. negative integer, giving position counting right. default returns last layer/attribute (assumption column created recently). name optional parameter specifies column used names named vector. Specified similar manner var. ... Arguments passed as_tibble.Spat()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract a single layer/attribute — pull.Spat","text":"vector number cells/geometries .data. SpatRaster objects, note default (na.rm = FALSE) remove empty cells, may need pass (na.rm = FALSE) .... See terra::.data.frame().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Extract a single layer/attribute — pull.Spat","text":"terra::values()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Extract a single layer/attribute — pull.Spat","text":"Implementation generic dplyr::pull() function. done coercing Spat* object tibble first (see as_tibble.Spat) using dplyr::pull() method tibble.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Extract a single layer/attribute — pull.Spat","text":"passing option na.rm = TRUE ..., cells value distinct NA extracted. See terra::.data.frame(). xy = TRUE option passed ..., two columns names x y (corresponding geographic coordinates cell) available position 1 2. Hence, pull(.data, 1) pull(.data, 1, xy = TRUE) return different result.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Extract a single layer/attribute — pull.Spat","text":"passing geom = \"WKT\"/geom = \"HEX\" ..., geometry SpatVector can pulled passing var = geometry. Similarly SpatRaster method, using geom = \"XY\" x,y coordinates can pulled var = x/var = y. See terra::.data.frame() options.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract a single layer/attribute — pull.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") r <- rast(f) # Extract second layer r %>% pull(2) %>% head() #> [1] 229 235 229 229 239 153 # With xy the first two cols are `x` (longitude) and `y` (latitude) r %>% pull(2, xy = TRUE) %>% head() #> [1] 5370160 5370160 5370160 5370160 5370160 5370160 # With renaming r %>% mutate(cat = cut(cyl_tile_3, c(0, 100, 300))) %>% pull(cyl_tile_3, name = cat) %>% head() #> (100,300] (100,300] (100,300] (100,300] (100,300] (100,300] #> 206 224 206 206 233 169"},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract CRS on WKT format — pull_crs","title":"Extract CRS on WKT format — pull_crs","text":"Extract WKT version CRS associated string, number sf/Spat* object. Well-known text (WKT) representation coordinate reference systems (CRS) character string identifies precisely parameters CRS. current standard used sf terra packages.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract CRS on WKT format — pull_crs","text":"","code":"pull_crs(.data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract CRS on WKT format — pull_crs","text":".data Input potentially including representing CRS. sf/sfc object, SpatRaster/SpatVector object, crs object sf::st_crs(), character (example proj4 string) integer (representing EPSG code). ... ignored","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract CRS on WKT format — pull_crs","text":"WKT representation corresponding CRS.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Extract CRS on WKT format — pull_crs","text":"Although WKT representation , sf terra API slightly differs. example, sf can : sf::st_transform(x, 25830) sf equivalent : terra::project(bb, \"epsg:25830\") Knowing WKT help smooth workflows working different packages object types.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"internals","dir":"Reference","previous_headings":"","what":"Internals","title":"Extract CRS on WKT format — pull_crs","text":"thin wrapper sf::st_crs() terra::crs().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract CRS on WKT format — pull_crs","text":"","code":"# sf objects sfobj <- sf::st_as_sfc(\"MULTIPOINT ((0 0), (1 1))\", crs = 4326) fromsf1 <- pull_crs(sfobj) fromsf2 <- pull_crs(sf::st_crs(sfobj)) # terra v <- terra::vect(sfobj) r <- terra::rast(v) fromterra1 <- pull_crs(v) fromterra2 <- pull_crs(r) # integers fromint <- pull_crs(4326) # Characters fromchar <- pull_crs(\"epsg:4326\") all( fromsf1 == fromsf2, fromsf2 == fromterra1, fromterra1 == fromterra2, fromterra2 == fromint, fromint == fromchar ) #> [1] TRUE cat(fromsf1) #> GEOGCRS[\"WGS 84\", #> ENSEMBLE[\"World Geodetic System 1984 ensemble\", #> MEMBER[\"World Geodetic System 1984 (Transit)\"], #> MEMBER[\"World Geodetic System 1984 (G730)\"], #> MEMBER[\"World Geodetic System 1984 (G873)\"], #> MEMBER[\"World Geodetic System 1984 (G1150)\"], #> MEMBER[\"World Geodetic System 1984 (G1674)\"], #> MEMBER[\"World Geodetic System 1984 (G1762)\"], #> MEMBER[\"World Geodetic System 1984 (G2139)\"], #> ELLIPSOID[\"WGS 84\",6378137,298.257223563, #> LENGTHUNIT[\"metre\",1]], #> ENSEMBLEACCURACY[2.0]], #> PRIMEM[\"Greenwich\",0, #> ANGLEUNIT[\"degree\",0.0174532925199433]], #> CS[ellipsoidal,2], #> AXIS[\"geodetic latitude (Lat)\",north, #> ORDER[1], #> ANGLEUNIT[\"degree\",0.0174532925199433]], #> AXIS[\"geodetic longitude (Lon)\",east, #> ORDER[2], #> ANGLEUNIT[\"degree\",0.0174532925199433]], #> USAGE[ #> SCOPE[\"Horizontal component of 3D system.\"], #> AREA[\"World.\"], #> BBOX[-90,-180,90,180]], #> ID[\"EPSG\",4326]]"},{"path":"https://dieghernan.github.io/tidyterra/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. dplyr anti_join, arrange, count, distinct, filter, full_join, glimpse, group_by, group_by_drop_default, group_data, group_indices, group_keys, group_rows, group_size, group_vars, groups, groups, inner_join, left_join, mutate, n_groups, pull, relocate, rename, rename_with, right_join, rowwise, select, semi_join, slice, slice_head, slice_max, slice_min, slice_sample, slice_tail, summarise, summarize, tally, transmute, ungroup ggplot2 aes, after_stat, autoplot, fortify tibble as_tibble tidyr drop_na, fill, pivot_longer, pivot_wider, replace_na","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Change layer/attribute order — relocate.Spat","title":"Change layer/attribute order — relocate.Spat","text":"Use relocate() change layer/attribute positions, using syntax select.Spat make easy move blocks layers/attributes .","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Change layer/attribute order — relocate.Spat","text":"","code":"# S3 method for class 'SpatRaster' relocate(.data, ..., .before = NULL, .after = NULL) # S3 method for class 'SpatVector' relocate(.data, ..., .before = NULL, .after = NULL)"},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Change layer/attribute order — relocate.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... layers/attributes move. ., . Destination layers/attributes selected .... Supplying neither move layers/attributes left-hand side; specifying error.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Change layer/attribute order — relocate.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Change layer/attribute order — relocate.Spat","text":"terra::subset(data, c(\"name_layer\", \"name_other_layer\"))","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Change layer/attribute order — relocate.Spat","text":"Implementation generic dplyr::relocate() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Change layer/attribute order — relocate.Spat","text":"Relocate layers SpatRaster.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Change layer/attribute order — relocate.Spat","text":"result SpatVector attributes different order.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Change layer/attribute order — relocate.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") spatrast <- rast(f) %>% mutate(aa = 1, bb = 2, cc = 3) names(spatrast) #> [1] \"cyl_tile_1\" \"cyl_tile_2\" \"cyl_tile_3\" \"aa\" \"bb\" #> [6] \"cc\" spatrast %>% relocate(bb, .before = cyl_tile_3) %>% relocate(cyl_tile_1, .after = last_col()) #> class : SpatRaster #> dimensions : 212, 261, 6 (nrow, ncol, nlyr) #> resolution : 2445.985, 2445.985 (x, y) #> extent : -812067, -173664.9, 4852834, 5371383 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : cyl_tile_2, bb, cyl_tile_3, aa, cc, cyl_tile_1 #> min values : 35, 2, 35, 1, 3, 35 #> max values : 251, 2, 250, 1, 3, 253"},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Rename layers/attributes — rename.Spat","title":"Rename layers/attributes — rename.Spat","text":"rename() changes names individual layers/attributes using new_name = old_name syntax; rename_with() renames layers/attributes using function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Rename layers/attributes — rename.Spat","text":"","code":"# S3 method for class 'SpatRaster' rename(.data, ...) # S3 method for class 'SpatRaster' rename_with(.data, .fn, .cols = everything(), ...) # S3 method for class 'SpatVector' rename(.data, ...) # S3 method for class 'SpatVector' rename_with(.data, .fn, .cols = everything(), ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Rename layers/attributes — rename.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... Depending function: rename.Spat*(): . Use new_name = old_name rename selected variables. rename_with(): additional arguments passed onto .fn. .fn function used transform selected .cols. return character vector length input. .cols Columns rename; defaults columns.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Rename layers/attributes — rename.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Rename layers/attributes — rename.Spat","text":"names(Spat*) <- c(\"\", \"b\", \"c\")","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Rename layers/attributes — rename.Spat","text":"Implementation generic dplyr::rename() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Rename layers/attributes — rename.Spat","text":"Rename layers SpatRaster.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Rename layers/attributes — rename.Spat","text":"result SpatVector renamed attributes function call.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Rename layers/attributes — rename.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") spatrast <- rast(f) %>% mutate(aa = 1, bb = 2, cc = 3) spatrast #> class : SpatRaster #> dimensions : 212, 261, 6 (nrow, ncol, nlyr) #> resolution : 2445.985, 2445.985 (x, y) #> extent : -812067, -173664.9, 4852834, 5371383 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : cyl_tile_1, cyl_tile_2, cyl_tile_3, aa, bb, cc #> min values : 35, 35, 35, 1, 2, 3 #> max values : 253, 251, 250, 1, 2, 3 spatrast %>% rename( this_first = cyl_tile_1, this_second = cyl_tile_2 ) #> class : SpatRaster #> dimensions : 212, 261, 6 (nrow, ncol, nlyr) #> resolution : 2445.985, 2445.985 (x, y) #> extent : -812067, -173664.9, 4852834, 5371383 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : this_first, this_second, cyl_tile_3, aa, bb, cc #> min values : 35, 35, 35, 1, 2, 3 #> max values : 253, 251, 250, 1, 2, 3 spatrast %>% rename_with( toupper, .cols = starts_with(\"c\") ) #> class : SpatRaster #> dimensions : 212, 261, 6 (nrow, ncol, nlyr) #> resolution : 2445.985, 2445.985 (x, y) #> extent : -812067, -173664.9, 4852834, 5371383 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : CYL_TILE_1, CYL_TILE_2, CYL_TILE_3, aa, bb, CC #> min values : 35, 35, 35, 1, 2, 3 #> max values : 253, 251, 250, 1, 2, 3"},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Replace NAs with specified values — replace_na.Spat","title":"Replace NAs with specified values — replace_na.Spat","text":"Replace NA values layers/attributes specified values","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Replace NAs with specified values — replace_na.Spat","text":"","code":"# S3 method for class 'SpatRaster' replace_na(data, replace = list(), ...) # S3 method for class 'SpatVector' replace_na(data, replace, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Replace NAs with specified values — replace_na.Spat","text":"data SpatRaster created terra::rast() SpatVector created terra::vect(). replace list values, one value layer/attribute NA values replaced. ... Ignored","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Replace NAs with specified values — replace_na.Spat","text":"Spat* object class data. Geometries spatial attributes preserved.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Replace NAs with specified values — replace_na.Spat","text":"Use r[.na(r)] <- ","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Replace NAs with specified values — replace_na.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) r %>% plot() r %>% replace_na(list(tavg_04 = 6, tavg_06 = 20)) %>% plot()"},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Group SpatVector objects by rows — rowwise.SpatVector","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"rowwise() allows compute SpatVector row---time. useful vectorised function exist. dplyr verbs implementation tidyterra preserve row-wise grouping, exception summarise.SpatVector(). can explicitly ungroup ungroup.SpatVector() as_tibble(), convert grouped SpatVector group_by.SpatVector().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"","code":"# S3 method for class 'SpatVector' rowwise(data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"data SpatVector object. See Methods. ... Variables preserved calling summarise.SpatVector(). typically set variables whose combination uniquely identify row. See dplyr::rowwise().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"SpatVector object additional attribute.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"See Details dplyr::rowwise().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"Implementation generic dplyr::rowwise() function SpatVector objects. mixing terra dplyr syntax row-wise SpatVector (.e, subsetting SpatVector like v[1:3,1:2]) groups attribute can corrupted. tidyterra try re-generate SpatVector. triggered next time use dplyr verb SpatVector. Note also operations (terra::spatSample()) create new SpatVector. cases, result preserve groups attribute. Use rowwise.SpatVector() re-group.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"","code":"library(terra) library(dplyr) v <- terra::vect(system.file(\"shape/nc.shp\", package = \"sf\")) # Select new births nb <- v %>% select(starts_with(\"NWBIR\")) %>% glimpse() #> # A SpatVector 100 x 2 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat NAD27 (EPSG:4267) #> # Extent (x / y) : ([84° 19' 25.87\" W / 75° 27' 25.12\" W] , [33° 52' 55.17\" N / 36° 35' 22.74\" N]) #> #> $ NWBIR74 10, 10, 208, 123, 1066, 954, 115, 254, 748, 160, 550, 1243, 93… #> $ NWBIR79 19, 12, 260, 145, 1197, 1237, 139, 371, 844, 176, 597, 1369, 1… # Compute the mean of NWBIR on each geometry nb %>% rowwise() %>% mutate(nb_mean = mean(c(NWBIR74, NWBIR79))) #> class : SpatVector #> geometry : polygons #> dimensions : 100, 3 (geometries, attributes) #> extent : -84.32385, -75.45698, 33.88199, 36.58965 (xmin, xmax, ymin, ymax) #> source : nc.shp #> coord. ref. : lon/lat NAD27 (EPSG:4267) #> names : NWBIR74 NWBIR79 nb_mean #> type : #> values : 10 19 14.5 #> 10 12 11 #> 208 260 234 # Additional examples # \\donttest{ # use c_across() to more easily select many variables nb %>% rowwise() %>% mutate(m = mean(c_across(NWBIR74:NWBIR79))) #> class : SpatVector #> geometry : polygons #> dimensions : 100, 3 (geometries, attributes) #> extent : -84.32385, -75.45698, 33.88199, 36.58965 (xmin, xmax, ymin, ymax) #> source : nc.shp #> coord. ref. : lon/lat NAD27 (EPSG:4267) #> names : NWBIR74 NWBIR79 m #> type : #> values : 10 19 14.5 #> 10 12 11 #> 208 260 234 # Compute the minimum of x and y in each row nb %>% rowwise() %>% mutate(min = min(c_across(NWBIR74:NWBIR79))) #> class : SpatVector #> geometry : polygons #> dimensions : 100, 3 (geometries, attributes) #> extent : -84.32385, -75.45698, 33.88199, 36.58965 (xmin, xmax, ymin, ymax) #> source : nc.shp #> coord. ref. : lon/lat NAD27 (EPSG:4267) #> names : NWBIR74 NWBIR79 min #> type : #> values : 10 19 10 #> 10 12 10 #> 208 260 208 # Summarising v %>% rowwise() %>% summarise(mean_bir = mean(BIR74, BIR79)) %>% glimpse() %>% autoplot(aes(fill = mean_bir)) #> # A SpatVector 100 x 1 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat NAD27 (EPSG:4267) #> # Extent (x / y) : ([84° 19' 25.87\" W / 75° 27' 25.12\" W] , [33° 52' 55.17\" N / 36° 35' 22.74\" N]) #> #> $ mean_bir 1091, 487, 3188, 508, 1421, 1452, 286, 420, 968, 1612, 1035, … # Supply a variable to be kept v %>% mutate(id2 = as.integer(CNTY_ID / 100)) %>% rowwise(id2) %>% summarise(mean_bir = mean(BIR74, BIR79)) %>% glimpse() %>% autoplot(aes(fill = as.factor(id2))) #> # A SpatVector 100 x 2 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat NAD27 (EPSG:4267) #> # Extent (x / y) : ([84° 19' 25.87\" W / 75° 27' 25.12\" W] , [33° 52' 55.17\" N / 36° 35' 22.74\" N]) #> #> Groups: id2 [2] #> $ id2 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 1… #> $ mean_bir 1091, 487, 3188, 508, 1421, 1452, 286, 420, 968, 1612, 1035, … # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_coltab.html","id":null,"dir":"Reference","previous_headings":"","what":"Discrete scales based in the color table of a SpatRaster — scale_coltab","title":"Discrete scales based in the color table of a SpatRaster — scale_coltab","text":"categorical SpatRaster objects may associated color table. function extract values. functions generates scales vector colors based color table terra::coltab() associated SpatRaster. can also get vector colors named corresponding factor get_coltab_pal(). Additional parameters ... passed ggplot2::discrete_scale(). Note tidyterra just documents selection additional parameters, check ggplot2::discrete_scale() see full range parameters accepted.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_coltab.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Discrete scales based in the color table of a SpatRaster — scale_coltab","text":"","code":"scale_fill_coltab( data, ..., alpha = 1, na.translate = FALSE, na.value = \"transparent\", drop = TRUE ) scale_colour_coltab( data, ..., alpha = 1, na.translate = FALSE, na.value = \"transparent\", drop = TRUE ) get_coltab_pal(x)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_coltab.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Discrete scales based in the color table of a SpatRaster — scale_coltab","text":"data, x SpatRaster one several color tables. See terra::.colors(). ... Arguments passed ggplot2::discrete_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. limits One : NULL use default scale values character vector defines possible values scale order function accepts existing (automatic) values returns new ones. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. alpha alpha transparency, number [0,1], see argument alpha hsv. na.translate NA values removed legend? Default TRUE. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. drop unused factor levels omitted scale? default (TRUE) removes unused factors.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_coltab.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Discrete scales based in the color table of a SpatRaster — scale_coltab","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_coltab.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Discrete scales based in the color table of a SpatRaster — scale_coltab","text":"","code":"library(terra) # Geological Eras # Spanish Geological Survey (IGME) r <- rast(system.file(\"extdata/cyl_era.tif\", package = \"tidyterra\")) plot(r) # Get coltab coltab_pal <- get_coltab_pal(r) coltab_pal #> Precambric-Paleozoic Paleozoic Paleozoic-Mesozoic #> \"#FFBFE9\" \"#9ADDCF\" \"#D79EBD\" #> Mesozoic Mesozoic-Cenozoic Cenozoic #> \"#A4FF74\" \"#FFD480\" \"#FFFFBF\" #> Undetermined #> \"#FFFFFF\" # \\donttest{ # With ggplot2 + tidyterra library(ggplot2) gg <- ggplot() + geom_spatraster(data = r) # Default plot gg # With coltabs gg + scale_fill_coltab(data = r) #> Scale for fill is already present. #> Adding another scale for fill, which will replace the existing scale. # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":null,"dir":"Reference","previous_headings":"","what":"Cross blended hypsometric tints scales — scale_cross_blended","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"Implementation cross blended hypsometric gradients presented doi:10.14714/CP69.20 . following fill scales palettes provided: scale_*_cross_blended_d(): discrete values. scale_*_cross_blended_c(): continuous values. scale_*_cross_blended_b(): binning continuous values. cross_blended.colors(): gradient color palette. See also grDevices::terrain.colors() details. additional set scales provided. scales can act hypsometric (bathymetric) tints. scale_*_cross_blended_tint_d(): discrete values. scale_*_cross_blended_tint_c(): continuous values. scale_*_cross_blended_tint_b(): binning continuous values. cross_blended.colors2(): gradient color palette. See also grDevices::terrain.colors() details. See Details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"","code":"scale_fill_cross_blended_d( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_cross_blended_d( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_cross_blended_c( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_cross_blended_c( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_cross_blended_b( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_cross_blended_b( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) cross_blended.colors(n, palette = \"cold_humid\", alpha = 1, rev = FALSE) scale_fill_cross_blended_tint_d( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_cross_blended_tint_d( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_cross_blended_tint_c( palette = \"cold_humid\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_cross_blended_tint_c( palette = \"cold_humid\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_cross_blended_tint_b( palette = \"cold_humid\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_cross_blended_tint_b( palette = \"cold_humid\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"coloursteps\" ) cross_blended.colors2(n, palette = \"cold_humid\", alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"Patterson, T., & Jenny, B. (2011). Development Rationale Cross-blended Hypsometric Tints. Cartographic Perspectives, (69), 31 - 46. doi:10.14714/CP69.20 . Patterson, T. (2004). Using Cross-blended Hypsometric Tints Generalized Environmental Mapping. Accessed June 10, 2022. https://www.shadedrelief.com/hypso/hypso.html","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"palette valid palette name. name matched list available palettes, ignoring upper vs. lower case. See cross_blended_hypsometric_tints_db info. Values available : \"arid\", \"cold_humid\", \"polar\", \"warm_humid\". ... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed. values colours evenly positioned along gradient vector gives position (0 1) colour colours vector. See rescale() convenience function map arbitrary range 0 1. limits One : NULL use default scale range numeric vector length two providing limits scale. Use NA refer existing minimum maximum function accepts existing (automatic) limits returns new limits. Also accepts rlang lambda function notation. Note setting limits positional scales remove data outside limits. purpose zoom, use limit argument coordinate system (see coord_cartesian()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"scale_*_cross_blended_tint_* palettes, position gradients limits palette redefined. Instead treating color palette continuous gradient, rescaled act hypsometric tint. rough description tints : Blue colors: Negative values. Green colors: 0 1.000 values. Browns: 1000 4.000 values. Whites: Values higher 4.000. following orientation vary depending palette definition (see cross_blended_hypsometric_tints_db example achieved). Note setup palette may always suitable specific data. example, SpatRaster small parts globe (limited range elevations) may well represented. example, SpatRaster range values [100, 200] appear almost uniform color. adjusted using limits/values parameters. cross_blended.colors2() provides gradient color palette distance colors different depending type color. contrast, cross_blended.colors() provides uniform gradient across colors. See Examples.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = cross_blended.colors(100, palette = \"arid\")) # Palette with uneven colors plot(volcano2_rast, col = cross_blended.colors2(100, palette = \"arid\")) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_cross_blended_c(palette = \"cold_humid\") # Use hypsometric tint version... ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_cross_blended_tint_c(palette = \"cold_humid\") # ...but not suitable for the range of the raster: adjust my_lims <- minmax(volcano2_rast) %>% as.integer() + c(-2, 2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_cross_blended_tint_c( palette = \"cold_humid\", limits = my_lims ) # Full map with true tints f_asia <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") asia <- rast(f_asia) ggplot() + geom_spatraster(data = asia) + scale_fill_cross_blended_tint_c( palette = \"warm_humid\", labels = scales::label_number(), breaks = c(-10000, 0, 5000, 8000), guide = guide_colorbar(reverse = TRUE) ) + labs(fill = \"elevation (m)\") + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" ) # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_cross_blended_b(breaks = seq(70, 200, 25), palette = \"arid\") # With limits and breaks ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_cross_blended_tint_b( breaks = seq(75, 200, 25), palette = \"arid\", limits = my_lims ) # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_cross_blended_d(na.value = \"gray10\", palette = \"cold_humid\") # Tint version ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_cross_blended_tint_d( na.value = \"gray10\", palette = \"cold_humid\" ) # } # Display all the cross-blended palettes pals <- unique(cross_blended_hypsometric_tints_db$pal) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = cross_blended.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar) # Display all the cross-blended palettes on version 2 pals <- unique(cross_blended_hypsometric_tints_db$pal) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = cross_blended.colors2(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":null,"dir":"Reference","previous_headings":"","what":"GRASS scales — scale_grass","title":"GRASS scales — scale_grass","text":"Implementation GRASS color tables. following fill scales palettes provided: scale_*_grass_d(): discrete values. scale_*_grass_c(): continuous values. scale_*_grass_b(): binning continuous values. grass.colors(): Gradient color palette. See also grDevices::terrain.colors() details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales. palettes implementation terra::map.pal(), default color palettes provided terra::plot() (terra > 1.7.78).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"GRASS scales — scale_grass","text":"","code":"scale_fill_grass_d( palette = \"viridis\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_grass_d( palette = \"viridis\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_grass_c( palette = \"viridis\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, use_grass_range = TRUE, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_grass_c( palette = \"viridis\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, use_grass_range = TRUE, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_grass_b( palette = \"viridis\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, use_grass_range = TRUE, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_grass_b( palette = \"viridis\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, use_grass_range = TRUE, na.value = \"transparent\", guide = \"coloursteps\" ) grass.colors(n, palette = \"viridis\", alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"GRASS scales — scale_grass","text":"Derived https://github.com/OSGeo/grass/tree/main/lib/gis/colors. See also r.color - GRASS GIS Manual.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"GRASS scales — scale_grass","text":"palette valid palette name. name matched list available palettes, ignoring upper vs. lower case. See grass_db info. ... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. values colours evenly positioned along gradient vector gives position (0 1) colour colours vector. See rescale() convenience function map arbitrary range 0 1. limits One : NULL use default scale range numeric vector length two providing limits scale. Use NA refer existing minimum maximum function accepts existing (automatic) limits returns new limits. Also accepts rlang lambda function notation. Note setting limits positional scales remove data outside limits. purpose zoom, use limit argument coordinate system (see coord_cartesian()). use_grass_range Logical. scale use suggested range plotting? See Details. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"GRASS scales — scale_grass","text":"corresponding ggplot2 layer values applied fill/colour aes().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"GRASS scales — scale_grass","text":"palettes mapped default specific range values (see grass_db). However, possible modify behaviour use_grass_range argument, FALSE color scales mapped range values color/fill aesthethics, See Examples.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"GRASS scales — scale_grass","text":"terra::map.pal()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"GRASS scales — scale_grass","text":"GRASS Development Team (2024). Geographic Resources Analysis Support System (GRASS) Software, Version 8.3.2. Open Source Geospatial Foundation, USA. https://grass.osgeo.org.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"GRASS scales — scale_grass","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = grass.colors(100, palette = \"haxby\")) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_grass_c(palette = \"terrain\") # Use with no default limits ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_grass_c(palette = \"terrain\", use_grass_range = FALSE) # Full map with true tints f_asia <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") asia <- rast(f_asia) ggplot() + geom_spatraster(data = asia) + scale_fill_grass_c( palette = \"srtm_plus\", labels = scales::label_number(), breaks = c(-10000, 0, 5000, 8000), guide = guide_colorbar(reverse = FALSE) ) + labs(fill = \"elevation (m)\") + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" ) # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_grass_b(breaks = seq(70, 200, 25), palette = \"sepia\") # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_grass_d(palette = \"soilmoisture\") # } # Display all the GRASS palettes data(\"grass_db\") pals_all <- unique(grass_db$pal) # In batches pals <- pals_all[c(1:25)] # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = grass.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar) # Second batch pals <- pals_all[-c(1:25)] ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = grass.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":null,"dir":"Reference","previous_headings":"","what":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"Implementation selection gradient palettes available cpt-city. following scales palettes provided: scale_*_hypso_d(): discrete values. scale_*_hypso_c(): continuous values. scale_*_hypso_b(): binning continuous values. hypso.colors(): gradient color palette. See also grDevices::terrain.colors() details. additional set scales provided. scales can act hypsometric (bathymetric) tints. scale_*_hypso_tint_d(): discrete values. scale_*_hypso_tint_c(): continuous values. scale_*_hypso_tint_b(): binning continuous values. hypso.colors2(): gradient color palette. See also grDevices::terrain.colors() details. See Details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"","code":"scale_fill_hypso_d( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_hypso_d( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_hypso_c( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_hypso_c( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_hypso_b( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_hypso_b( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) hypso.colors(n, palette = \"etopo1_hypso\", alpha = 1, rev = FALSE) scale_fill_hypso_tint_d( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_hypso_tint_d( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_hypso_tint_c( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_hypso_tint_c( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_hypso_tint_b( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_hypso_tint_b( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"coloursteps\" ) hypso.colors2(n, palette = \"etopo1_hypso\", alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"cpt-city: http://seaviewsensing.com/pub/cpt-city/.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"palette valid palette name. name matched list available palettes, ignoring upper vs. lower case. See hypsometric_tints_db info. Values available : \"arctic\", \"arctic_bathy\", \"arctic_hypso\", \"c3t1\", \"colombia\", \"colombia_bathy\", \"colombia_hypso\", \"dem_poster\", \"dem_print\", \"dem_screen\", \"etopo1\", \"etopo1_bathy\", \"etopo1_hypso\", \"gmt_globe\", \"gmt_globe_bathy\", \"gmt_globe_hypso\", \"meyers\", \"meyers_bathy\", \"meyers_hypso\", \"moon\", \"moon_bathy\", \"moon_hypso\", \"nordisk-familjebok\", \"nordisk-familjebok_bathy\", \"nordisk-familjebok_hypso\", \"pakistan\", \"spain\", \"usgs-gswa2\", \"utah_1\", \"wiki-2.0\", \"wiki-2.0_bathy\", \"wiki-2.0_hypso\", \"wiki-schwarzwald-cont\". ... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed. values colours evenly positioned along gradient vector gives position (0 1) colour colours vector. See rescale() convenience function map arbitrary range 0 1. limits One : NULL use default scale range numeric vector length two providing limits scale. Use NA refer existing minimum maximum function accepts existing (automatic) limits returns new limits. Also accepts rlang lambda function notation. Note setting limits positional scales remove data outside limits. purpose zoom, use limit argument coordinate system (see coord_cartesian()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"scale_*_hypso_tint_* palettes, position gradients limits palette redefined. Instead treating color palette continuous gradient, rescaled act hypsometric tint. rough description tints : Blue colors: Negative values. Green colors: 0 1.000 values. Browns: 1000 4.000 values. Whites: Values higher 4.000. following orientation vary depending palette definition (see hypsometric_tints_db example achieved). Note setup palette may always suitable specific data. example, SpatRaster small parts globe (limited range elevations) may well represented. example, SpatRaster range values [100, 200] appear almost uniform color. adjusted using limits/values parameters. hypso.colors2() provides gradient color palette distance colors different depending type color. contrast, hypso.colors() provides uniform gradient across colors. See Examples.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = hypso.colors(100, palette = \"wiki-2.0_hypso\")) # Palette with uneven colors plot(volcano2_rast, col = hypso.colors2(100, palette = \"wiki-2.0_hypso\")) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_hypso_c(palette = \"colombia_hypso\") # Use hypsometric tint version... ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_hypso_tint_c(palette = \"colombia_hypso\") # ...but not suitable for the range of the raster: adjust my_lims <- minmax(volcano2_rast) %>% as.integer() + c(-2, 2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_hypso_tint_c( palette = \"colombia_hypso\", limits = my_lims ) # Full map with true tints f_asia <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") asia <- rast(f_asia) ggplot() + geom_spatraster(data = asia) + scale_fill_hypso_tint_c( palette = \"etopo1\", labels = scales::label_number(), breaks = c(-10000, 0, 5000, 8000), guide = guide_colorbar(reverse = TRUE) ) + labs(fill = \"elevation (m)\") + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" ) # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_hypso_b(breaks = seq(70, 200, 25), palette = \"wiki-2.0_hypso\") # With limits and breaks ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_hypso_tint_b( breaks = seq(75, 200, 25), palette = \"wiki-2.0_hypso\", limits = my_lims ) # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_hypso_d(na.value = \"gray10\", palette = \"dem_poster\") # Tint version ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_hypso_tint_d(na.value = \"gray10\", palette = \"dem_poster\") # } # Display all the cpl_city palettes pals <- unique(hypsometric_tints_db$pal) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = hypso.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar) # Display all the cpl_city palettes on version 2 pals <- unique(hypsometric_tints_db$pal) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = hypso.colors2(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":null,"dir":"Reference","previous_headings":"","what":"Gradient scales from princess color schemes — scale_princess","title":"Gradient scales from princess color schemes — scale_princess","text":"Implementation gradient palettes presented https://leahsmyth.github.io/Princess-Colour-Schemes/index.html. Three scales provided: scale_*_princess_d(): discrete values. scale_*_princess_c(): continuous values. scale_*_princess_b(): binning continuous values. Additionally, color palette princess.colors() provided. See also grDevices::terrain.colors() details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Gradient scales from princess color schemes — scale_princess","text":"","code":"scale_fill_princess_d( palette = \"snow\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_princess_d( palette = \"snow\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_princess_c( palette = \"snow\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_princess_c( palette = \"snow\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_princess_b( palette = \"snow\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_princess_b( palette = \"snow\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) princess.colors(n, palette = \"snow\", alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Gradient scales from princess color schemes — scale_princess","text":"https://github.com/LeahSmyth/Princess-Colour-Schemes.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Gradient scales from princess color schemes — scale_princess","text":"palette valid palette name. name matched list available palettes, ignoring upper vs. lower case. Values available : \"snow\", \"ella\", \"bell\", \"aura\", \"denmark\", \"france\", \"arabia\", \"america\", \"asia\", \"neworleans\", \"punz\", \"scotland\", \"cold\", \"norge\", \"maori\". ... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. limits One : NULL use default scale values character vector defines possible values scale order function accepts existing (automatic) values returns new ones. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Gradient scales from princess color schemes — scale_princess","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Gradient scales from princess color schemes — scale_princess","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = princess.colors(100)) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_princess_c() # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_princess_b(breaks = seq(70, 200, 10), palette = \"denmark\") # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_princess_d(na.value = \"gray10\", palette = \"maori\") # } # Display all the princess palettes pals <- unique(princess_db$pal) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = princess.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_terrain.html","id":null,"dir":"Reference","previous_headings":"","what":"Terrain colour scales from grDevices — scale_terrain","title":"Terrain colour scales from grDevices — scale_terrain","text":"Implementation classic color palette terrain.colors(): scale_*_terrain_d(): discrete values. scale_*_terrain_c(): continuous values. scale_*_terrain_b(): binning continuous values. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_terrain.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Terrain colour scales from grDevices — scale_terrain","text":"","code":"scale_fill_terrain_d( ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_terrain_d( ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_terrain_c( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_terrain_c( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_terrain_b( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_terrain_b( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" )"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_terrain.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Terrain colour scales from grDevices — scale_terrain","text":"... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. limits One : NULL use default scale values character vector defines possible values scale order function accepts existing (automatic) values returns new ones. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_terrain.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Terrain colour scales from grDevices — scale_terrain","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_terrain.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Terrain colour scales from grDevices — scale_terrain","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_terrain_c() # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_terrain_b(breaks = seq(70, 200, 10)) # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_terrain_d(na.value = \"gray10\") # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":null,"dir":"Reference","previous_headings":"","what":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"Implementation gradient palettes provided WhiteboxTools. Three scales provided: scale_*_whitebox_d(): discrete values. scale_*_whitebox_c(): continuous values. scale_*_whitebox_b(): binning continuous values. Additionally, color palette whitebox.colors() provided. See also grDevices::terrain.colors() details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"","code":"scale_fill_whitebox_d( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_whitebox_d( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_whitebox_c( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_whitebox_c( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_whitebox_b( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_whitebox_b( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) whitebox.colors(n, palette = \"high_relief\", alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"https://github.com/jblindsay/whitebox-tools, MIT License. Copyright (c) 2017-2021 John Lindsay.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"palette valid palette name. name matched list available palettes, ignoring upper vs. lower case. Values available : \"atlas\", \"high_relief\", \"arid\", \"soft\", \"muted\", \"purple\", \"viridi\", \"gn_yl\", \"pi_y_g\", \"bl_yl_rd\", \"deep\". ... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. limits One : NULL use default scale values character vector defines possible values scale order function accepts existing (automatic) values returns new ones. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = whitebox.colors(100)) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_whitebox_c() # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_whitebox_b(breaks = seq(70, 200, 10), palette = \"atlas\") # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_whitebox_d(na.value = \"gray10\", palette = \"soft\") # } # Display all the whitebox palettes pals <- c( \"atlas\", \"high_relief\", \"arid\", \"soft\", \"muted\", \"purple\", \"viridi\", \"gn_yl\", \"pi_y_g\", \"bl_yl_rd\", \"deep\" ) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = whitebox.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_wiki.html","id":null,"dir":"Reference","previous_headings":"","what":"Gradient scales from Wikipedia color schemes — scale_color_coltab","title":"Gradient scales from Wikipedia color schemes — scale_color_coltab","text":"Implementation based Wikipedia Colorimetric conventions topographic maps. Three scales provided: scale_*_wiki_d(): discrete values. scale_*_wiki_c(): continuous values. scale_*_wiki_b(): binning continuous values. Additionally, color palette wiki.colors() provided. See also grDevices::terrain.colors() details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_wiki.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Gradient scales from Wikipedia color schemes — scale_color_coltab","text":"","code":"scale_fill_wiki_d( ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_wiki_d( ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_wiki_c( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_wiki_c( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_wiki_b( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_wiki_b( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) wiki.colors(n, alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_wiki.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Gradient scales from Wikipedia color schemes — scale_color_coltab","text":"... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. limits One : NULL use default scale values character vector defines possible values scale order function accepts existing (automatic) values returns new ones. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. na.translate NA values removed legend? Default TRUE. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. drop unused factor levels omitted scale? default (TRUE) removes unused factors. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_wiki.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Gradient scales from Wikipedia color schemes — scale_color_coltab","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_wiki.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Gradient scales from Wikipedia color schemes — scale_color_coltab","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = wiki.colors(100)) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_wiki_c() # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_wiki_b(breaks = seq(70, 200, 10)) # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_wiki_d(na.value = \"gray10\") # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Subset layers/attributes of Spat* objects — select.Spat","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"Select (optionally rename) attributes/layers Spat* objects, using concise mini-language. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"","code":"# S3 method for class 'SpatRaster' select(.data, ...) # S3 method for class 'SpatVector' select(.data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Subset layers/attributes of Spat* objects — select.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... One unquoted expressions separated commas. Layer/attribute names can used positions Spat* object, expressions like x:y can used select range layers/attributes.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"terra::subset()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"Implementation generic dplyr::select() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"Select (rename) layers SpatRaster. result SpatRaster extent, resolution crs .data. number (possibly name) layers modified.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"result SpatVector selected (possibly renamed) attributes function call.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"","code":"library(terra) # SpatRaster method spatrast <- rast( crs = \"EPSG:3857\", nrows = 10, ncols = 10, extent = c(100, 200, 100, 200), nlyr = 6, vals = seq_len(10 * 10 * 6) ) spatrast %>% select(1) #> class : SpatRaster #> dimensions : 10, 10, 1 (nrow, ncol, nlyr) #> resolution : 10, 10 (x, y) #> extent : 100, 200, 100, 200 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> name : lyr.1 #> min value : 1 #> max value : 100 # By name spatrast %>% select(lyr.1:lyr.4) #> class : SpatRaster #> dimensions : 10, 10, 4 (nrow, ncol, nlyr) #> resolution : 10, 10 (x, y) #> extent : 100, 200, 100, 200 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : lyr.1, lyr.2, lyr.3, lyr.4 #> min values : 1, 101, 201, 301 #> max values : 100, 200, 300, 400 # Rename spatrast %>% select(a = lyr.1, c = lyr.6) #> class : SpatRaster #> dimensions : 10, 10, 2 (nrow, ncol, nlyr) #> resolution : 10, 10 (x, y) #> extent : 100, 200, 100, 200 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : a, c #> min values : 1, 501 #> max values : 100, 600 # SpatVector method f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- vect(f) v #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos #> ES-LE 24 Leon v %>% select(1, 3) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 2 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 name #> type : #> values : ES-AV Avila #> ES-BU Burgos #> ES-LE Leon v %>% select(iso2, name2 = cpro) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 2 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 name2 #> type : #> values : ES-AV 05 #> ES-BU 09 #> ES-LE 24"},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Subset cells/rows/columns/geometries using their positions — slice.Spat","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"slice() methods lets index cells/rows/columns/geometries (integer) locations. allows select, remove, duplicate dimensions Spat* object. want slice SpatRaster geographic coordinates use filter.SpatRaster() method. accompanied number helpers common use cases: slice_head() slice_tail() select first last cells/geometries. slice_sample() randomly selects cells/geometries. slice_rows() slice_cols() allow subset entire rows columns, SpatRaster. slice_colrows() subsets regions SpatRaster row column position SpatRaster. can get skeleton SpatRaster cell, column row index as_coordinates(). See Methods details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"","code":"# S3 method for class 'SpatRaster' slice(.data, ..., .preserve = FALSE, .keep_extent = FALSE) # S3 method for class 'SpatVector' slice(.data, ..., .preserve = FALSE) # S3 method for class 'SpatRaster' slice_head(.data, ..., n, prop, .keep_extent = FALSE) # S3 method for class 'SpatVector' slice_head(.data, ..., n, prop) # S3 method for class 'SpatRaster' slice_tail(.data, ..., n, prop, .keep_extent = FALSE) # S3 method for class 'SpatVector' slice_tail(.data, ..., n, prop) # S3 method for class 'SpatRaster' slice_min( .data, order_by, ..., n, prop, with_ties = TRUE, .keep_extent = FALSE, na.rm = TRUE ) # S3 method for class 'SpatVector' slice_min(.data, order_by, ..., n, prop, with_ties = TRUE, na_rm = FALSE) # S3 method for class 'SpatRaster' slice_max( .data, order_by, ..., n, prop, with_ties = TRUE, .keep_extent = FALSE, na.rm = TRUE ) # S3 method for class 'SpatVector' slice_max(.data, order_by, ..., n, prop, with_ties = TRUE, na_rm = FALSE) # S3 method for class 'SpatRaster' slice_sample( .data, ..., n, prop, weight_by = NULL, replace = FALSE, .keep_extent = FALSE ) # S3 method for class 'SpatVector' slice_sample(.data, ..., n, prop, weight_by = NULL, replace = FALSE) slice_rows(.data, ...) # S3 method for class 'SpatRaster' slice_rows(.data, ..., .keep_extent = FALSE) slice_cols(.data, ...) # S3 method for class 'SpatRaster' slice_cols(.data, ..., .keep_extent = FALSE) slice_colrows(.data, ...) # S3 method for class 'SpatRaster' slice_colrows(.data, ..., cols, rows, .keep_extent = FALSE, inverse = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... Integer row values. Provide either positive values keep, negative values drop. values provided must either positive negative. Indices beyond number rows input silently ignored. See Methods. .preserve Ignored Spat* objects. .keep_extent extent resulting SpatRaster kept? See also terra::trim(), terra::extend(). n, prop Provide either n, number rows, prop, proportion rows select. neither supplied, n = 1 used. n greater number rows group (prop > 1), result silently truncated group size. prop rounded towards zero generate integer number rows. negative value n prop subtracted group size. example, n = -2 group 5 rows select 5 - 2 = 3 rows; prop = -0.25 8 rows select 8 * (1 - 0.25) = 6 rows. order_by Variable function variables order . order multiple variables, wrap data frame tibble. with_ties ties kept together? default, TRUE, may return rows request. Use FALSE ignore ties, return first n rows. na.rm Logical, cells present value NA removed computing slice_min()/slice_max()?. default TRUE. na_rm missing values order_by removed result? FALSE, NA values sorted end (like arrange()), included insufficient non-missing values reach n/prop. weight_by Sampling weights. must evaluate vector non-negative numbers length input. Weights automatically standardised sum 1. replace sampling performed (TRUE) without (FALSE, default) replacement. cols, rows Integer col/row values SpatRaster inverse TRUE, .data inverse-masked given selection. See terra::mask().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"terra::subset(), terra::spatSample()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"Implementation generic dplyr::slice() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"result SpatRaster crs resolution input cell values selected cells/columns/rows preserved. Use .keep_extent = TRUE preserve extent .data output. non-selected cells present value NA.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"result SpatVector attributes selected geometries preserved. .data grouped SpatVector, operation performed group, (e.g.) slice_head(df, n = 5) select first five rows group.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) # Slice first 100 cells r %>% slice(1:100) %>% plot() # Rows r %>% slice_rows(1:30) %>% plot() # Cols r %>% slice_cols(-(20:50)) %>% plot() # Spatial sample r %>% slice_sample(prop = 0.2) %>% plot() # Slice regions r %>% slice_colrows( cols = c(20:40, 60:80), rows = -c(1:20, 30:50) ) %>% plot() # Group wise operation with SpatVectors-------------------------------------- v <- terra::vect(system.file(\"ex/lux.shp\", package = \"terra\")) # \\donttest{ glimpse(v) %>% autoplot(aes(fill = NAME_1)) #> # A SpatVector 12 x 6 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 44' 38.9\" E / 6° 31' 41.71\" E] , [49° 26' 52.11\" N / 50° 10' 53.84\" N]) #> #> $ ID_1 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3 #> $ NAME_1 \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Gr… #> $ ID_2 1, 2, 3, 4, 5, 6, 7, 12, 8, 9, 10, 11 #> $ NAME_2 \"Clervaux\", \"Diekirch\", \"Redange\", \"Vianden\", \"Wiltz\", \"Echtern… #> $ AREA 312, 218, 259, 76, 263, 188, 129, 210, 185, 251, 237, 233 #> $ POP 18081, 32543, 18664, 5163, 16735, 18899, 22366, 29828, 48187, 1… gv <- v %>% group_by(NAME_1) # All slice helpers operate per group, silently truncating to the group size gv %>% slice_head(n = 1) %>% glimpse() %>% autoplot(aes(fill = NAME_1)) #> # A SpatVector 3 x 6 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 49' 34.44\" E / 6° 31' 41.71\" E] , [49° 32' 55.33\" N / 50° 10' 53.84\" N]) #> #> Groups: NAME_1 [3] #> $ ID_1 1, 2, 3 #> $ NAME_1 \"Diekirch\", \"Grevenmacher\", \"Luxembourg\" #> $ ID_2 1, 6, 8 #> $ NAME_2 \"Clervaux\", \"Echternach\", \"Capellen\" #> $ AREA 312, 188, 185 #> $ POP 18081, 18899, 48187 gv %>% slice_tail(n = 1) %>% glimpse() %>% autoplot(aes(fill = NAME_1)) #> # A SpatVector 3 x 6 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 44' 38.9\" E / 6° 30' 59.35\" E] , [49° 35' 13.15\" N / 50° 2' 10.76\" N]) #> #> Groups: NAME_1 [3] #> $ ID_1 1, 2, 3 #> $ NAME_1 \"Diekirch\", \"Grevenmacher\", \"Luxembourg\" #> $ ID_2 5, 12, 11 #> $ NAME_2 \"Wiltz\", \"Grevenmacher\", \"Mersch\" #> $ AREA 263, 210, 233 #> $ POP 16735, 29828, 32112 gv %>% slice_min(AREA, n = 1) %>% glimpse() %>% autoplot(aes(fill = NAME_1)) #> # A SpatVector 3 x 6 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 51' 7.49\" E / 6° 22' 54.12\" E] , [49° 27' 53.95\" N / 49° 59' 2.98\" N]) #> #> Groups: NAME_1 [3] #> $ ID_1 1, 2, 3 #> $ NAME_1 \"Diekirch\", \"Grevenmacher\", \"Luxembourg\" #> $ ID_2 4, 7, 8 #> $ NAME_2 \"Vianden\", \"Remich\", \"Capellen\" #> $ AREA 76, 129, 185 #> $ POP 5163, 22366, 48187 gv %>% slice_max(AREA, n = 1) %>% glimpse() %>% autoplot(aes(fill = NAME_1)) #> # A SpatVector 3 x 6 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 48' 37.74\" E / 6° 30' 59.35\" E] , [49° 26' 52.11\" N / 50° 10' 53.84\" N]) #> #> Groups: NAME_1 [3] #> $ ID_1 1, 2, 3 #> $ NAME_1 \"Diekirch\", \"Grevenmacher\", \"Luxembourg\" #> $ ID_2 1, 12, 9 #> $ NAME_2 \"Clervaux\", \"Grevenmacher\", \"Esch-sur-Alzette\" #> $ AREA 312, 210, 251 #> $ POP 18081, 29828, 176820 # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract coordinates from SpatVector objects — stat_spat_coordinates","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"stat_spat_coordinates() extracts coordinates SpatVector objects summarises one pair coordinates (x y) per geometry.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"","code":"stat_spat_coordinates( mapping = aes(), data = NULL, geom = \"point\", position = \"identity\", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )"},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"mapping Set aesthetic mappings created aes(). specified inherit.aes = TRUE (default), combined default mapping top level plot. must supply mapping plot mapping. data SpatVector object, see terra::vect(). geom geometric object use display data layer. using stat_*() function construct layer, geom argument can used override default coupling stats geoms. geom argument accepts following: Geom ggproto subclass, example GeomPoint. string naming geom. give geom string, strip function name geom_ prefix. example, use geom_point(), give geom \"point\". information ways specify geom, see layer geom documentation. position position adjustment use data layer. can used various ways, including prevent overplotting improving display. position argument accepts following: result calling position function, position_jitter(). method allows passing extra arguments position. string naming position adjustment. give position string, strip function name position_ prefix. example, use position_jitter(), give position \"jitter\". information ways specify position, see layer position documentation. na.rm FALSE, default, missing values removed warning. TRUE, missing values silently removed. show.legend logical. layer included legends? NA, default, includes aesthetics mapped. FALSE never includes, TRUE always includes. can also set one \"polygon\", \"line\", \"point\" override default legend. inherit.aes FALSE, overrides default aesthetics, rather combining . useful helper functions define data aesthetics inherit behaviour default plot specification, e.g. borders(). ... arguments passed ggplot2::stat_sf_coordinates().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"Wrapper ggplot2::stat_sf_coordinates(). See ggplot2::stat_sf_coordinates() details.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"","code":"# \\donttest{ cyl <- terra::vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) library(ggplot2) ggplot(cyl) + stat_spat_coordinates() ggplot(cyl) + geom_errorbarh( aes( geometry = geometry, xmin = after_stat(x) - 50000, xmax = after_stat(x) + 50000, y = after_stat(y), height = 10000 ), stat = \"sf_coordinates\" ) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"summarise() creates new SpatVector. returns one geometry combination grouping variables; grouping variables, output single geometry summarising observations input combining geometries SpatVector. contain one column grouping variable one column summary statistics specified. summarise.SpatVector() summarize.SpatVector() synonyms","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"","code":"# S3 method for class 'SpatVector' summarise(.data, ..., .by = NULL, .groups = NULL, .dissolve = TRUE) # S3 method for class 'SpatVector' summarize(.data, ..., .by = NULL, .groups = NULL, .dissolve = TRUE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":".data SpatVector. ... Name-value pairs summary functions. name name variable result. value can : vector length 1, e.g. min(x), n(), sum(.na(y)). data frame, add multiple columns single expression. Returning values size 0 >1 deprecated 1.1.0. Please use reframe() instead. .Ignored method ( dplyr). .groups See dplyr::summarise() .dissolve logical. borders aggregated geometries dissolved?","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"terra::aggregate()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"Implementation generic dplyr::summarise() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"Similarly implementation sf function can used dissolve geometries (.dissolve = TRUE) create MULTI versions geometries (.dissolve = FALSE). See Examples.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"","code":"library(terra) library(ggplot2) v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) # Grouped gr_v <- v %>% mutate(start_with_s = substr(name, 1, 1) == \"S\") %>% group_by(start_with_s) # Dissolving diss <- gr_v %>% summarise(n = dplyr::n(), mean = mean(as.double(cpro))) diss #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : start_with_s n mean #> type : #> values : FALSE 6 28 #> TRUE 3 39.67 autoplot(diss, aes(fill = start_with_s)) + ggplot2::ggtitle(\"Dissolved\") # Not dissolving no_diss <- gr_v %>% summarise(n = dplyr::n(), mean = mean(as.double(cpro)), .dissolve = FALSE) # Same statistic no_diss #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : start_with_s n mean #> type : #> values : FALSE 6 28 #> TRUE 3 39.67 autoplot(no_diss, aes(fill = start_with_s)) + ggplot2::ggtitle(\"Not Dissolved\")"},{"path":"https://dieghernan.github.io/tidyterra/reference/tidyterra-package.html","id":null,"dir":"Reference","previous_headings":"","what":"tidyterra: 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' Objects — tidyterra-package","title":"tidyterra: 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' Objects — tidyterra-package","text":"Extension 'tidyverse' 'SpatRaster' 'SpatVector' objects 'terra' package. includes also new 'geom_' functions provide convenient way visualizing 'terra' objects 'ggplot2'.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/tidyterra-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"tidyterra: 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' Objects — tidyterra-package","text":"Maintainer: Diego Hernangómez diego.hernangomezherrero@gmail.com (ORCID) [copyright holder] contributors: Dewey Dunnington (ORCID) (ggspatial code) [contributor] ggplot2 authors (contour code) [copyright holder]","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/volcano2.html","id":null,"dir":"Reference","previous_headings":"","what":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","title":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","text":"Probably already know volcano dataset. dataset provides updated information Maungawhau (Mt. Eden) Toitu Te Whenua Land Information New Zealand, Government's agency provides free online access New Zealand’s --date land seabed data.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/volcano2.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","text":"matrix 174 rows 122 columns. value corresponding altitude meters.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/volcano2.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","text":"Auckland LiDAR 1m DEM (2013). DEM LiDAR data Auckland region captured 2013. original data downsampled resolution 5m due disk space constrains. Data License: CC 4.0.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/volcano2.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","text":"Information needed regenerating original SpatRaster file: resolution: c(5, 5) extent: 1756969, 1757579, 5917003, 5917873 (xmin, xmax, ymin, ymax) coord. ref. : NZGD2000 / New Zealand Transverse Mercator 2000 (EPSG:2193)","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/volcano2.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","text":"","code":"data(\"volcano2\") filled.contour(volcano2, color.palette = hypso.colors, asp = 1) title(main = \"volcano2 data: filled contour map\") # Geo-tag # Empty raster volcano2_raster <- terra::rast(volcano2) terra::crs(volcano2_raster) <- pull_crs(2193) terra::ext(volcano2_raster) <- c(1756968, 1757576, 5917000, 5917872) names(volcano2_raster) <- \"volcano2\" library(ggplot2) ggplot() + geom_spatraster(data = volcano2_raster) + scale_fill_hypso_c() + labs( title = \"volcano2 SpatRaster\", subtitle = \"Georeferenced\", fill = \"Elevation (m)\" )"},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-062","dir":"Changelog","previous_headings":"","what":"tidyterra 0.6.2","title":"tidyterra 0.6.2","text":"Add (limited) support SpatGraticule (see terra::graticule()) #155. New arguments geom_spatraster_rgb(): stretch zlim. See terra::plotRGB() clarification. geom_spatraster() suggests geom_spatraster_rgb() SpatRaster RGB specification detected (terra::.RGB() TRUE)","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-061","dir":"Changelog","previous_headings":"","what":"tidyterra 0.6.1","title":"tidyterra 0.6.1","text":"CRAN release: 2024-06-08 grass_db scale_fill_grass_c() family. implementation terra::map.pal(), default palette terra::plot() (> 1.7.78). autoplot.SpatRaster() now uses also grass_db default palette. Add scale_fill_princess_c() scale family. Fix tests.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-060","dir":"Changelog","previous_headings":"","what":"tidyterra 0.6.0","title":"tidyterra 0.6.0","text":"CRAN release: 2024-04-22 Requires ggplot2 (>= 3.5.0). pivot_longer.SpatVector() pivot_wider.SpatVector(). fill.SpatVector(). New geom geom_spatraster_contour_text() implemented top isoband::isolines_grob() . glimpse.SpatRaster() glimpse.SpatVector() now displays information using ?tibble::print.tbl_df approach header footer. body still displayed transposed dplyr::glimpse(). See pillar::tbl_format_header() pillar::tbl_format_footer() examples. as_sf() converts SpatVector sf object additional tbl_df class pretty printing. fortify.SpatRaster() gains new argument pivot allows better integration ggplot2 geoms pivoting. wrapper tidyr::pivot_longer(). Tidy documentation. metR added Suggests.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-052","dir":"Changelog","previous_headings":"","what":"tidyterra 0.5.2","title":"tidyterra 0.5.2","text":"CRAN release: 2024-01-19 Adapt tests ggplot2 3.5.0 (#129) @teunbrand. Reduce package size, specially relevant external raster asia.tif.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-051","dir":"Changelog","previous_headings":"","what":"tidyterra 0.5.1","title":"tidyterra 0.5.1","text":"CRAN release: 2023-12-15 Adjust tests as_sf() (#124).","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-050","dir":"Changelog","previous_headings":"","what":"tidyterra 0.5.0","title":"tidyterra 0.5.0","text":"CRAN release: 2023-11-21 tidyterra accepted JOSS. Please use result citation(\"tidyterra\") following string: Hernangómez, D. (2023). “Using tidyverse terra objects: tidyterra package.” Journal Open Source Software, 8(91), 5751. ISSN 2475-9066, https://doi.org/10.21105/joss.05751 changes version: autoplot.SpatRaster() can detect now SpatRaster objects color tables. geom_spatraster() can detect now SpatRaster objects color tables. New scales plotting SpatRaster objects color tables: scale_fill_coltab() rest family scales (colour). tidyverse verbs keeps associated coltab SpatRaster. default discrete scales tidyterra now following setup: na.translate = FALSE. default, non-discrete (e.g. continuous breaks) scales tidyterra now na.value = \"transparent\" (#120). Enhanced glimpse.Spat() meta-information type geometry, crs, etc. New messaging interface thanks cli package.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-041","dir":"Changelog","previous_headings":"","what":"tidyterra 0.4.1","title":"tidyterra 0.4.1","text":"Release JOSS paper. relevant changes.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-040","dir":"Changelog","previous_headings":"","what":"tidyterra 0.4.0","title":"tidyterra 0.4.0","text":"CRAN release: 2023-03-17 glimpse.SpatVector() arrange.SpatVector() distinct.SpatVector() inner_join.SpatVector(), left_join.SpatVector(), right_join.SpatVector() full_join.SpatVector() semi_join.SpatVector() anti_join.SpatVector() summarise.SpatVector() rowwise.SpatVector() group_by.SpatVector(),ungroup.SpatVector() count.SpatVector(), tally.SpatVector() bind_spat_cols(), bind_spat_rows() Already implemented methods now works dplyr::group_by(). Internal review code. Now methods rely sf::st_as_sf() coercion. fact coercion object classes avoided much possible. New glimpse.SpatRaster() method SpatRaster. as_spatvector() as_sf() is_grouped_spatvector()","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-032","dir":"Changelog","previous_headings":"","what":"tidyterra 0.3.2","title":"tidyterra 0.3.2","text":"CRAN release: 2023-02-24 Fix bug pull_crs() returned \"NA\" sf objects field equal NA (#74). Improve docs scales_* (#73) . Remove dependency crayon package (superseded) favor cli. Remove tidyverse Suggests.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-031","dir":"Changelog","previous_headings":"","what":"tidyterra 0.3.1","title":"tidyterra 0.3.1","text":"CRAN release: 2022-11-09 autoplot.SpatRaster() now smarter identifying type plot produce. Can still overridden parameters. Methods fortifying SpatRaster SpatVector objects: fortify.SpatRaster(), fortify.SpatVector(). Three additional palettes included hypso.colors(): \"artic\", \"meyers\" \"nordisk-familjebok\". Added colour scales palettes: scale_colour_*. Remove use ggplot2::aes_string(). Adapt geom_spatraster_contour() geom_spatraster_contour_filled() changes introduced ggplot2 (3.4.0), notably adoption linewidth = .2, default.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-030","dir":"Changelog","previous_headings":"","what":"tidyterra 0.3.0","title":"tidyterra 0.3.0","text":"CRAN release: 2022-10-12 Package back CRAN. Libraries dplyr, tidyr, tibble attached default. Needed functions reexported instead. Now geom_spatraster() possible avoid default fill layer using geom_spatraster(fill = NA) geom_spatraster(aes(fill = NULL)). aes(fill = ggplot2::after_stat()) now works geom_spatraster(). Internal: Better handling aes() layers Add new function stat_spatraster(). Reduce size external files.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-022","dir":"Changelog","previous_headings":"","what":"tidyterra 0.2.2","title":"tidyterra 0.2.2","text":"CRAN release: 2022-09-29 Changes dplyr, tibble tidyr attached. Now packages listed ‘Depends’ attached tidyterra library require called. Messages load can suppressed suppressPackageStartupMessages(library(tidyterra)).","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-021","dir":"Changelog","previous_headings":"","what":"tidyterra 0.2.1","title":"tidyterra 0.2.1","text":"CRAN release: 2022-09-23 Now geom_spatraster_rgb() works facet_wrap() (#35) Improve faceting plot facets created using non-Spat* layers. Precompute vignettes.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-020","dir":"Changelog","previous_headings":"","what":"tidyterra 0.2.0","title":"tidyterra 0.2.0","text":"CRAN release: 2022-06-21 Recreate extdata/volcano2.tif using official DEM information New Zealand. Source: Auckland LiDAR 1m DEM (2013). Add volcano2 dataset. Fix errors slice_min() slice_max() SpatRaster objects (#20). Also add new parameter na.rm. scale_fill_hypso_c() scale_fill_whitebox_c() scale_fill_wiki_c() scale_fill_cross_blended_c() Add new asia.tif file extdata.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-010","dir":"Changelog","previous_headings":"","what":"tidyterra 0.1.0","title":"tidyterra 0.1.0","text":"CRAN release: 2022-05-24 Add DOI. CRAN release.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-001","dir":"Changelog","previous_headings":"","what":"tidyterra 0.0.1","title":"tidyterra 0.0.1","text":"Conversion tibble avoided much possible. Internally use data.tables instead tibbles. package compatible dtplyr. as_spatraster() handles tibbles characters factors. Simplification tests geom_spatraster() geom_spatraster_rgb(). pull() transmute() rename() geom_spatraster_contour() family.","code":""}] +[{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"source","dir":"Articles","previous_headings":"Example data","what":"Source","title":"tidyterra FAQs","text":"article uses sample LiDAR Scotland Phase 5 - DSM provided Scottish Remote Sensing Portal. data made available Open Government Licence v3.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"about-the-file","dir":"Articles","previous_headings":"Example data","what":"About the file","title":"tidyterra FAQs","text":"file holyroodpark.tif represents DEM1 Holyrood Park, Edinburgh (Scotland), including Arthur’s Seat, extinct volcano, pretty much famous Maungawhau / Mount Eden volcano represented datasets::volcano. original file cropped -sampled demo purposes, holyroodpark.tif available online https://github.com/dieghernan/tidyterra/tree/main/data-raw folder.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"nas-remove","dir":"Articles","previous_headings":"","what":"NA values are shown in gray color","title":"tidyterra FAQs","text":"default behavior produced ggplot2 package. tidyterra color scales (.e., scale_fill_whitebox_c(), etc.), default parameter na.value set \"transparent\", prevents NA values filled2.","code":"library(terra) library(tidyterra) #> Error in get(paste0(generic, \".\", class), envir = get_method_env()) : #> object 'type_sum.accel' not found library(ggplot2) # Get a raster data from Holyrood Park, Edinburgh holyrood <- \"holyroodpark.tif\" r <- holyrood %>% rast() %>% filter(elevation > 80 & elevation < 180) # Default def <- ggplot() + geom_spatraster(data = r) def + labs( title = \"Default on ggplot2\", subtitle = \"NA values in grey\" ) # Modify with scales def + scale_fill_continuous(na.value = \"transparent\") + labs( title = \"Default colors on ggplot2\", subtitle = \"But NAs are not plotted\" ) # Use a different scale provided by ggplot2 def + scale_fill_viridis_c(na.value = \"orange\") + labs( title = \"Use any fill_* scale of ggplot2\", subtitle = \"Note that na.value = 'orange'\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"label-contour","dir":"Articles","previous_headings":"","what":"Labeling contours","title":"tidyterra FAQs","text":"Use geom_spatraster_contour_text() :","code":"library(terra) library(tidyterra) library(ggplot2) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) ggplot() + geom_spatraster_contour_text(data = r) + labs(title = \"Labelling contours\") # With options and aes # Use a labeller function so only selected breaks are labelled labeller <- function(labs) { # Must return a function function(x) { x[!x %in% labs] <- NA scales::label_comma(suffix = \" m.\")(x) } } # Common labels across ggplot labs <- c(100, 140, 180, 220) ggplot(r) + geom_spatraster_contour_text( data = r, aes( linewidth = after_stat(level), size = after_stat(level), color = after_stat(level) ), breaks = seq(100, 250, 10), # Just label some isolines label_format = labeller(labs = labs), family = \"mono\", fontface = \"bold\" ) + scale_linewidth_continuous(range = c(0.1, 0.5), breaks = labs) + scale_color_gradient(low = \"grey50\", high = \"grey10\", breaks = labs) + scale_size_continuous(range = c(2, 3), breaks = labs) + # Integrate scales guides( linewidth = guide_legend(\"meters\"), size = guide_legend(\"meters\"), color = guide_legend(\"meters\") ) + # Theme and titles theme_bw() + theme(text = element_text(family = \"mono\")) + labs( title = \"Labelling contours\", subtitle = \"With options: b/w plot\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"other-alternatives","dir":"Articles","previous_headings":"Labeling contours","what":"Other alternatives","title":"tidyterra FAQs","text":"Thanks fortify.SpatRaster() can use SpatRaster straight away metR package (see Hexagonal grids geoms). Use parameter(s) bins/binwidth/breaks align labels lines:","code":"library(metR) br <- seq(100, 250, 10) labs <- c(100, 140, 180, 220) # Replicate previous map with tidyterra + metR strategy ggplot(r, aes(x, y)) + geom_spatraster_contour( data = r, aes( linewidth = after_stat(level), color = after_stat(level) ), breaks = br, # Don't inherit fortified aes inherit.aes = FALSE ) + geom_text_contour( aes( z = elevation, color = after_stat(level), size = after_stat(level) ), breaks = br, # Text options check_overlap = TRUE, label.placer = label_placer_minmax(), stroke = 0.3, stroke.colour = \"white\", family = \"mono\", fontface = \"bold\", key_glyph = \"path\" ) + scale_linewidth_continuous(range = c(0.1, 0.5), breaks = labs) + scale_color_gradient(low = \"grey50\", high = \"grey10\", breaks = labs) + scale_size_continuous(range = c(2, 3), breaks = labs) + # Integrate scales guides( linewidth = guide_legend(\"meters\"), size = guide_legend(\"meters\"), color = guide_legend(\"meters\") ) + # Theme and titles theme_bw() + theme(text = element_text(family = \"mono\")) + labs( title = \"Labelling contours\", subtitle = \"tidyterra and metR: b/w plot\", x = \"\", y = \"\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"use-scale","dir":"Articles","previous_headings":"","what":"Using a different color scale","title":"tidyterra FAQs","text":"Since tidyterra leverages ggplot2, please refer ggplot2 use scales:","code":"library(terra) library(tidyterra) library(ggplot2) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) # Hillshade with grey colors slope <- terrain(r, \"slope\", unit = \"radians\") aspect <- terrain(r, \"aspect\", unit = \"radians\") hill <- shade(slope, aspect, 10, 340) ggplot() + geom_spatraster(data = hill, show.legend = FALSE) + # Note the scale, grey colours scale_fill_gradientn( colours = grey(0:100 / 100), na.value = \"transparent\" ) + labs(title = \"A hillshade plot with grey colors\")"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"can-i-change-the-default-palette-of-my-maps","dir":"Articles","previous_headings":"","what":"Can I change the default palette of my maps?","title":"tidyterra FAQs","text":"Yes, use options(\"ggplot2.continuous.fill\") modify default colors session.","code":"library(terra) library(tidyterra) library(ggplot2) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) p <- ggplot() + geom_spatraster(data = r) # Set options tmp <- getOption(\"ggplot2.continuous.fill\") # store current setting options(ggplot2.continuous.fill = scale_fill_grass_c) p # restore previous setting options(ggplot2.continuous.fill = tmp) p"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"blurry-tiles","dir":"Articles","previous_headings":"","what":"My map tiles are blurry","title":"tidyterra FAQs","text":"probably related tile rather package. base tiles provided EPSG:3857, check first tile CRS different one. EPSG:3857 may indication tile reprojected, implied sort sampling causes blurriness data. Also, modify parameter maxcell avoid resampling force ggplot2 map EPSG:3857 ggplot2::coord_sf(crs = 3857):","code":"library(terra) library(tidyterra) library(ggplot2) library(sf) library(maptiles) # Get a tile from a point on sf format p <- st_point(c(-3.166011, 55.945235)) %>% st_sfc(crs = 4326) %>% st_buffer(500) tile1 <- get_tiles(p, provider = \"OpenStreetMap\", zoom = 14, cachedir = \".\", crop = TRUE ) ggplot() + geom_spatraster_rgb(data = tile1) + labs(title = \"This is a bit blurry...\") + theme_void() st_crs(tile1)$epsg #> [1] 4326 # The tile was in EPSG 4326 # get tile in 3857 p2 <- st_transform(p, 3857) tile2 <- get_tiles(p2, provider = \"OpenStreetMap\", zoom = 14, cachedir = \".\", crop = TRUE ) st_crs(tile2)$epsg #> [1] 3857 # Now the tile is EPSG:3857 ggplot() + geom_spatraster_rgb(data = tile2, maxcell = Inf) + # Force crs to be 3857 coord_sf(crs = 3857) + labs(title = \"...compared with this one\") + theme_void()"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"axis-degrees","dir":"Articles","previous_headings":"","what":"Avoid degrees labeling on axis","title":"tidyterra FAQs","text":", ggplot2 default, can modified ggplot2::coord_sf(datum) argument:","code":"library(terra) library(tidyterra) library(ggplot2) library(sf) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) ggplot() + geom_spatraster(data = r) + labs( title = \"Axis auto-converted to lon/lat\", subtitle = paste(\"But SpatRaster is EPSG:\", st_crs(r)$epsg) ) # Use datum ggplot() + geom_spatraster(data = r) + coord_sf(datum = pull_crs(r)) + labs( title = \"Axis on the units of the SpatRaster\", subtitle = paste(\"EPSG:\", st_crs(r)$epsg) )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"axis-breaks","dir":"Articles","previous_headings":"","what":"Modifying the number of breaks on axis","title":"tidyterra FAQs","text":"best option pass custom breaks ggplot2::scale_x_continous() ggplot2::scale_y_continous(). need provide breaks lon/lat even data projected. See also ggplot2/issues/4622:","code":"library(terra) library(tidyterra) library(ggplot2) library(sf) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) ggplot() + geom_spatraster(data = r) + labs(title = \"Default axis breaks\") # Modify y breaks with extent projected in EPSG:4326 # Get extent ext <- r %>% project(\"EPSG:4326\", mask = TRUE) %>% ext() %>% as.vector() ggplot() + geom_spatraster(data = r) + scale_x_continuous( expand = expansion(mult = 0.05), breaks = scales::breaks_pretty(n = 3)(ext[c(\"xmin\", \"xmax\")]) ) + labs(title = \"Three breaks on x (¿?)\")"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"plotting-a-spatraster-with-color-tables","dir":"Articles","previous_headings":"","what":"Plotting a SpatRaster with color tables","title":"tidyterra FAQs","text":"tidyterra several ways handle SpatRaster objects. use file clc_edinburgh.tif, available online https://github.com/dieghernan/tidyterra/tree/main/data-raw folder, representing information Corine Land Cover Dataset (2018) city Edinburgh3.","code":"library(terra) library(tidyterra) library(ggplot2) # Get a SpatRaster with coltab r_coltab <- rast(\"clc_edinburgh.tif\") has.colors(r_coltab) #> [1] TRUE r_coltab #> class : SpatRaster #> dimensions : 196, 311, 1 (nrow, ncol, nlyr) #> resolution : 178.8719, 177.9949 (x, y) #> extent : -380397.3, -324768.1, 7533021, 7567908 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source : clc_edinburgh.tif #> color table : 1 #> categories : label #> name : label #> min value : Continuous urban fabric #> max value : Sea and ocean # Native handling by terra packages plot(r_coltab) # A. autoplot autoplot(r_coltab, maxcell = Inf) + guides(fill = guide_legend(ncol = 1)) + ggtitle(\"autoplot method\") # B. geom_spatraster ggplot() + geom_spatraster(data = r_coltab, maxcell = Inf) + guides(fill = guide_legend(ncol = 1)) + ggtitle(\"geom_spatraster method\") # C. Using scale_fill_coltab g <- ggplot() + geom_spatraster(data = r_coltab, use_coltab = FALSE, maxcell = Inf) + guides(fill = guide_legend(ncol = 1)) g # But... g + scale_fill_coltab(data = r_coltab) + ggtitle(\"scale_fill_coltab method\") # D. Extract named colors and scale_fill_manual cols <- get_coltab_pal(r_coltab) cols #> Continuous urban fabric #> \"#E6004D\" #> Discontinuous urban fabric #> \"#FF0000\" #> Industrial or commercial units #> \"#CC4DF2\" #> Road and rail networks and associated land #> \"#CC0000\" #> Port areas #> \"#E6CCCC\" #> Airports #> \"#E6CCE6\" #> Mineral extraction sites #> \"#A600CC\" #> Dump sites #> \"#A64D00\" #> Construction sites #> \"#FF4DFF\" #> Green urban areas #> \"#FFA6FF\" #> Sport and leisure facilities #> \"#FFE6FF\" #> Non-irrigated arable land #> \"#FFFFA8\" #> Pastures #> \"#E6E64D\" #> Broad-leaved forest #> \"#80FF00\" #> Coniferous forest #> \"#00A600\" #> Mixed forest #> \"#4DFF00\" #> Natural grasslands #> \"#CCF24D\" #> Moors and heathland #> \"#A6FF80\" #> Bare rocks #> \"#CCCCCC\" #> Intertidal flats #> \"#A6A6E6\" #> Water bodies #> \"#80F2E6\" #> Estuaries #> \"#A6FFE6\" #> Sea and ocean #> \"#E6F2FF\" scales::show_col(cols) # And now g + scale_fill_manual( values = cols, na.value = \"transparent\", na.translate = FALSE ) + ggtitle(\"scale_fill_manual method\")"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"gganimate","dir":"Articles","previous_headings":"","what":"Use with gganimate","title":"tidyterra FAQs","text":"Sure! See example (thanks @frzambra):","code":"library(gganimate) library(tidyterra) library(geodata) library(ggplot2) temp <- worldclim_country(\"che\", \"tavg\", path = \".\") che_cont <- gadm(\"che\", level = 0, path = \".\") temp_m <- crop(temp, che_cont, mask = TRUE) names(temp_m) <- month.name anim <- ggplot() + geom_spatraster(data = temp_m) + scale_fill_viridis_c( option = \"inferno\", na.value = \"transparent\", labels = scales::label_number(suffix = \"º C\") ) + transition_manual(lyr) + theme_bw() + theme( axis.text = element_blank(), axis.ticks = element_blank() ) + labs( title = \"Avg temp Switzerland: {current_frame}\", fill = \"\" ) gganimate::animate(anim, duration = 12, device = \"ragg_png\")"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"north-arrows-and-scale-bar","dir":"Articles","previous_headings":"","what":"North arrows and scale bar","title":"tidyterra FAQs","text":"tidyterra provide graphical objects ggplot2 plots. However, can use ggspatial functions (ggspatial::annotation_north_arrow() ggspatial::annotation_scale()):","code":"library(terra) library(tidyterra) library(ggplot2) library(ggspatial) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) autoplot(r) + annotation_north_arrow( which_north = TRUE, pad_x = unit(0.8, \"npc\"), pad_y = unit(0.75, \"npc\"), style = north_arrow_fancy_orienteering() ) + annotation_scale( height = unit(0.015, \"npc\"), width_hint = 0.5, pad_x = unit(0.07, \"npc\"), pad_y = unit(0.07, \"npc\"), text_cex = .8 )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"how-to-overlay-a-spatraster-over-a-rgb-tile","dir":"Articles","previous_headings":"","what":"How to overlay a SpatRaster over a RGB tile","title":"tidyterra FAQs","text":"quite straightforward, just use geom_spatraster_rgb() command just create layer: can create another variations binned legends filled contours (see geom_spatraster_contour_filled()):","code":"library(terra) library(tidyterra) library(ggplot2) library(sf) # Get example data library(maptiles) library(geodata) # Area of interest aoi <- gadm(country = \"CHE\", path = \".\", level = 0) %>% project(\"EPSG:3857\") # Tile rgb_tile <- get_tiles(aoi, crop = TRUE, provider = \"Esri.WorldShadedRelief\", zoom = 8, project = FALSE, cachedir = \".\" ) # Clim (mean prec) clim <- worldclim_country(\"CHE\", var = \"prec\", path = \".\") %>% project(rgb_tile) %>% mask(aoi) %>% terra::mean() # Labels cap_lab <- paste0( c( \"Tiles © Esri - Source: Esri\", \"Data: © Copyright 2020-2022, worldclim.org.\" ), collapse = \"\\n\" ) tit_lab <- \"Average precipitation in Switzerland\" ggplot(aoi) + geom_spatraster_rgb(data = rgb_tile, alpha = 1) + geom_spatraster(data = clim) + geom_spatvector(fill = NA) + scale_fill_whitebox_c( palette = \"deep\", alpha = 0.5, labels = scales::label_number(suffix = \" mm.\") ) + coord_sf(expand = FALSE) + labs( title = tit_lab, subtitle = \"With continuous overlay\", fill = \"Precipitation\", caption = cap_lab ) # Binned ggplot(aoi) + geom_spatraster_rgb(data = rgb_tile, alpha = 1) + geom_spatraster(data = clim) + geom_spatvector(fill = NA) + scale_fill_whitebox_b( palette = \"deep\", alpha = 0.5, n.breaks = 4, labels = scales::label_number(suffix = \" mm.\") ) + coord_sf(expand = FALSE) + labs( title = tit_lab, subtitle = \"With overlay: binned legend\", fill = \"Precipitation\", caption = cap_lab ) # Filled contour ggplot(aoi) + geom_spatraster_rgb(data = rgb_tile, alpha = 1) + geom_spatraster_contour_filled(data = clim, bins = 4) + geom_spatvector(fill = NA) + coord_sf(expand = FALSE) + scale_fill_whitebox_d( palette = \"deep\", alpha = 0.5, guide = guide_legend(reverse = TRUE) ) + labs( title = tit_lab, subtitle = \"With overlay and filled contour\", fill = \"Precipitation (mm.)\", caption = cap_lab )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"fort","dir":"Articles","previous_headings":"","what":"Hexagonal grids (and other geoms)","title":"tidyterra FAQs","text":"concept cells SpatRaster rectangular, possible create SpatRaster .e. hexagonal cells. possible create plot hexagonal cells thanks fortify.SpatRaster() stat_summary_hex(). Additional work needed adjust final plot, specifically needed also use coord_sf(): Note need make direct call fortify.SpatRaster(), since function implicitly invoked ggplot2 using ggplot(data = a_spatraster). Thanks extension mechanism, possible use additional geoms stats provided ggplot2:","code":"library(terra) library(tidyterra) library(ggplot2) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood) # With hex grid ggplot(r, aes(x, y, z = elevation)) + stat_summary_hex( fun = mean, color = NA, linewidth = 0, # Bins size determines the number of cells displayed bins = 30 ) + coord_sf(crs = pull_crs(r)) + labs( title = \"Hexagonal SpatRaster\", subtitle = \"Using fortify (implicit) and stat_summary_hex\", x = NULL, y = NULL ) # Point plot ggplot(r, aes(x, y, z = elevation), maxcell = 1000) + geom_point(aes(size = elevation, alpha = elevation), fill = \"darkblue\", color = \"grey50\", shape = 21 ) + coord_sf(crs = pull_crs(r)) + scale_radius(range = c(1, 5)) + scale_alpha(range = c(0.01, 1)) + labs( title = \"SpatRaster as points\", subtitle = \"Using fortify (implicit)\", x = NULL, y = NULL )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"tidyterra-and-metr","dir":"Articles","previous_headings":"Hexagonal grids (and other geoms)","what":"tidyterra and metR","title":"tidyterra FAQs","text":"metR package also provides ggplot2 extensions, mainly focused analysis meteorological fields. shown previously (see Labeling contours) possible use packages provide rich plots. section shows demos.","code":"# load libraries and files library(terra) library(tidyterra) library(ggplot2) library(metR) holyrood <- \"holyroodpark.tif\" r <- rast(holyrood)"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"metrgeom_contour_tanaka","dir":"Articles","previous_headings":"Hexagonal grids (and other geoms) > tidyterra and metR","what":"metR::geom_contour_tanaka()","title":"tidyterra FAQs","text":"","code":"ggplot(r, aes(x, y)) + geom_spatraster(data = r, inherit.aes = FALSE) + geom_contour_tanaka(aes(z = elevation), breaks = seq(0, 250, 25)) + scale_fill_viridis_c(option = \"magma\") + labs(x = \"\", y = \"\", title = \"tidyterra and metR: tanaka contours\") # Using geom_spatraster_contour_filled ggplot(r, aes(x, y)) + geom_spatraster_contour_filled( data = r, inherit.aes = FALSE, breaks = seq(0, 250, 50) ) + geom_contour_tanaka(aes(z = elevation), breaks = seq(0, 250, 10), sun.angle = -90, dark = \"gray50\" ) + scale_fill_viridis_d(option = \"cividis\") + labs( x = \"\", y = \"\", title = \"tidyterra and metR: tanaka contours\", subtitle = \"with geom_contour_filled\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"metrgeom_relief","dir":"Articles","previous_headings":"Hexagonal grids (and other geoms) > tidyterra and metR","what":"metR::geom_relief()","title":"tidyterra FAQs","text":"","code":"ggplot(r, aes(x, y)) + geom_relief(aes(z = elevation)) + geom_spatraster( data = r, inherit.aes = FALSE, aes(alpha = after_stat(value)) ) + scale_fill_cross_blended_c(breaks = seq(0, 250, 25)) + scale_alpha(range = c(1, 0.25)) + guides(alpha = \"none\", fill = guide_legend(reverse = TRUE)) + labs(x = \"\", y = \"\", title = \"tidyterra and metR: reliefs\")"},{"path":"https://dieghernan.github.io/tidyterra/articles/faqs.html","id":"session-info","dir":"Articles","previous_headings":"","what":"Session info","title":"tidyterra FAQs","text":"","code":"#> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.4.2 (2024-10-31 ucrt) #> os Windows Server 2022 x64 (build 20348) #> system x86_64, mingw32 #> ui RTerm #> language en #> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz UTC #> date 2025-01-08 #> pandoc 3.1.11 @ C:/HOSTED~1/windows/pandoc/31F387~1.11/x64/PANDOC~1.11/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> backports 1.5.0 2024-05-23 [1] RSPM #> bslib 0.8.0 2024-07-29 [1] RSPM #> cachem 1.1.0 2024-05-16 [1] RSPM #> checkmate 2.3.2 2024-07-29 [1] RSPM #> class 7.3-22 2023-05-03 [3] CRAN (R 4.4.2) #> classInt 0.4-10 2023-09-05 [1] RSPM #> cli 3.6.3 2024-06-21 [1] RSPM #> codetools 0.2-20 2024-03-31 [3] CRAN (R 4.4.2) #> colorspace 2.1-1 2024-07-26 [1] RSPM #> data.table 1.16.4 2024-12-06 [1] RSPM #> DBI 1.2.3 2024-06-02 [1] RSPM #> desc 1.4.3 2023-12-10 [1] RSPM #> digest 0.6.37 2024-08-19 [1] RSPM #> dplyr 1.1.4 2023-11-17 [1] RSPM #> e1071 1.7-16 2024-09-16 [1] RSPM #> evaluate 1.0.1 2024-10-10 [1] RSPM #> farver 2.1.2 2024-05-13 [1] RSPM #> fastmap 1.2.0 2024-05-15 [1] RSPM #> fs 1.6.5 2024-10-30 [1] RSPM #> generics 0.1.3 2022-07-05 [1] RSPM #> geodata * 0.6-2 2024-06-10 [1] RSPM #> ggplot2 * 3.5.1 2024-04-23 [1] RSPM #> ggspatial * 1.1.9 2023-08-17 [1] RSPM #> glue 1.8.0 2024-09-30 [1] RSPM #> gtable 0.3.6 2024-10-25 [1] RSPM #> hexbin 1.28.5 2024-11-13 [1] RSPM #> htmltools 0.5.8.1 2024-04-04 [1] RSPM #> isoband 0.2.7 2022-12-20 [1] RSPM #> jquerylib 0.1.4 2021-04-26 [1] RSPM #> jsonlite 1.8.9 2024-09-20 [1] RSPM #> KernSmooth 2.23-24 2024-05-17 [3] CRAN (R 4.4.2) #> knitr 1.49 2024-11-08 [1] RSPM #> labeling 0.4.3 2023-08-29 [1] RSPM #> lattice 0.22-6 2024-03-20 [3] CRAN (R 4.4.2) #> lifecycle 1.0.4 2023-11-07 [1] RSPM #> magrittr 2.0.3 2022-03-30 [1] RSPM #> maptiles * 0.8.0 2024-10-22 [1] RSPM #> memoise 2.0.1 2021-11-26 [1] RSPM #> metR * 0.16.0 2024-10-14 [1] RSPM #> munsell 0.5.1 2024-04-01 [1] RSPM #> pillar 1.10.0 2024-12-17 [1] RSPM #> pkgconfig 2.0.3 2019-09-22 [1] RSPM #> pkgdown 2.1.1 2024-09-17 [1] RSPM #> plyr 1.8.9 2023-10-02 [1] RSPM #> proxy 0.4-27 2022-06-09 [1] RSPM #> purrr 1.0.2 2023-08-10 [1] RSPM #> R.cache 0.16.0 2022-07-21 [1] RSPM #> R.methodsS3 1.8.2 2022-06-13 [1] RSPM #> R.oo 1.27.0 2024-11-01 [1] RSPM #> R.utils 2.12.3 2023-11-18 [1] RSPM #> R6 2.5.1 2021-08-19 [1] RSPM #> ragg 1.3.3 2024-09-11 [1] RSPM #> Rcpp 1.0.13-1 2024-11-02 [1] RSPM #> rlang 1.1.4 2024-06-04 [1] RSPM #> rmarkdown 2.29 2024-11-04 [1] RSPM #> s2 1.1.7 2024-07-17 [1] RSPM #> sass 0.4.9 2024-03-15 [1] RSPM #> scales 1.3.0 2023-11-28 [1] RSPM #> sessioninfo * 1.2.2 2021-12-06 [1] any (@1.2.2) #> sf * 1.0-19 2024-11-05 [1] RSPM #> styler 1.10.3 2024-04-07 [1] RSPM #> systemfonts 1.1.0 2024-05-15 [1] RSPM #> terra * 1.8-5 2024-12-12 [1] RSPM #> textshaping 0.4.1 2024-12-06 [1] RSPM #> tibble 3.2.1 2023-03-20 [1] RSPM #> tidyr 1.3.1 2024-01-24 [1] RSPM #> tidyselect 1.2.1 2024-03-11 [1] RSPM #> tidyterra * 0.6.2 2025-01-08 [1] local #> units 0.8-5 2023-11-28 [1] RSPM #> vctrs 0.6.5 2023-12-01 [1] RSPM #> viridisLite 0.4.2 2023-05-02 [1] RSPM #> withr 3.0.2 2024-10-28 [1] RSPM #> wk 0.9.4 2024-10-11 [1] RSPM #> xfun 0.49 2024-10-31 [1] RSPM #> yaml 2.3.10 2024-07-26 [1] RSPM #> #> [1] D:/a/_temp/Library #> [2] C:/R/site-library #> [3] C:/R/library #> #> ──────────────────────────────────────────────────────────────────────────────"},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_terrain_-and-scale_fill_wiki_","dir":"Articles","previous_headings":"","what":"scale_fill_terrain_* and scale_fill_wiki_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_terrain_c() scale_fill_wiki_c() info.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_whitebox_","dir":"Articles","previous_headings":"","what":"scale_fill_whitebox_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_whitebox_c() info.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_hypso_","dir":"Articles","previous_headings":"","what":"scale_fill_hypso_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_hypso_c() info.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_cross_blended_","dir":"Articles","previous_headings":"","what":"scale_fill_cross_blended_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_cross_blended_c() info.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_grass_","dir":"Articles","previous_headings":"","what":"scale_fill_grass_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_grass_c() info. Plots produced using use_grass_range = FALSE.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"scale_fill_princess_","dir":"Articles","previous_headings":"","what":"scale_fill_princess_*","title":"Gradient palettes in tidyterra","text":"Check scale_fill_princess_c() info.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/palettes.html","id":"session-info","dir":"Articles","previous_headings":"","what":"Session info","title":"Gradient palettes in tidyterra","text":"","code":"#> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.4.2 (2024-10-31 ucrt) #> os Windows Server 2022 x64 (build 20348) #> system x86_64, mingw32 #> ui RTerm #> language en #> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz UTC #> date 2025-01-08 #> pandoc 3.1.11 @ C:/HOSTED~1/windows/pandoc/31F387~1.11/x64/PANDOC~1.11/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> bslib 0.8.0 2024-07-29 [1] RSPM #> cachem 1.1.0 2024-05-16 [1] RSPM #> class 7.3-22 2023-05-03 [3] CRAN (R 4.4.2) #> classInt 0.4-10 2023-09-05 [1] RSPM #> cli 3.6.3 2024-06-21 [1] RSPM #> codetools 0.2-20 2024-03-31 [3] CRAN (R 4.4.2) #> colorspace 2.1-1 2024-07-26 [1] RSPM #> data.table 1.16.4 2024-12-06 [1] RSPM #> DBI 1.2.3 2024-06-02 [1] RSPM #> desc 1.4.3 2023-12-10 [1] RSPM #> digest 0.6.37 2024-08-19 [1] RSPM #> dplyr 1.1.4 2023-11-17 [1] RSPM #> e1071 1.7-16 2024-09-16 [1] RSPM #> evaluate 1.0.1 2024-10-10 [1] RSPM #> farver 2.1.2 2024-05-13 [1] RSPM #> fastmap 1.2.0 2024-05-15 [1] RSPM #> fs 1.6.5 2024-10-30 [1] RSPM #> generics 0.1.3 2022-07-05 [1] RSPM #> ggplot2 * 3.5.1 2024-04-23 [1] RSPM #> glue 1.8.0 2024-09-30 [1] RSPM #> gtable 0.3.6 2024-10-25 [1] RSPM #> htmltools 0.5.8.1 2024-04-04 [1] RSPM #> jquerylib 0.1.4 2021-04-26 [1] RSPM #> jsonlite 1.8.9 2024-09-20 [1] RSPM #> KernSmooth 2.23-24 2024-05-17 [3] CRAN (R 4.4.2) #> knitr 1.49 2024-11-08 [1] RSPM #> labeling 0.4.3 2023-08-29 [1] RSPM #> lifecycle 1.0.4 2023-11-07 [1] RSPM #> magrittr 2.0.3 2022-03-30 [1] RSPM #> munsell 0.5.1 2024-04-01 [1] RSPM #> pillar 1.10.0 2024-12-17 [1] RSPM #> pkgconfig 2.0.3 2019-09-22 [1] RSPM #> pkgdown 2.1.1 2024-09-17 [1] RSPM #> proxy 0.4-27 2022-06-09 [1] RSPM #> purrr 1.0.2 2023-08-10 [1] RSPM #> R.cache 0.16.0 2022-07-21 [1] RSPM #> R.methodsS3 1.8.2 2022-06-13 [1] RSPM #> R.oo 1.27.0 2024-11-01 [1] RSPM #> R.utils 2.12.3 2023-11-18 [1] RSPM #> R6 2.5.1 2021-08-19 [1] RSPM #> ragg 1.3.3 2024-09-11 [1] RSPM #> Rcpp 1.0.13-1 2024-11-02 [1] RSPM #> rlang 1.1.4 2024-06-04 [1] RSPM #> rmarkdown 2.29 2024-11-04 [1] RSPM #> sass 0.4.9 2024-03-15 [1] RSPM #> scales 1.3.0 2023-11-28 [1] RSPM #> sessioninfo * 1.2.2 2021-12-06 [1] any (@1.2.2) #> sf 1.0-19 2024-11-05 [1] RSPM #> styler 1.10.3 2024-04-07 [1] RSPM #> systemfonts 1.1.0 2024-05-15 [1] RSPM #> terra 1.8-5 2024-12-12 [1] RSPM #> textshaping 0.4.1 2024-12-06 [1] RSPM #> tibble 3.2.1 2023-03-20 [1] RSPM #> tidyr 1.3.1 2024-01-24 [1] RSPM #> tidyselect 1.2.1 2024-03-11 [1] RSPM #> tidyterra * 0.6.2 2025-01-08 [1] local #> units 0.8-5 2023-11-28 [1] RSPM #> vctrs 0.6.5 2023-12-01 [1] RSPM #> withr 3.0.2 2024-10-28 [1] RSPM #> xfun 0.49 2024-10-31 [1] RSPM #> yaml 2.3.10 2024-07-26 [1] RSPM #> #> [1] D:/a/_temp/Library #> [2] C:/R/site-library #> [3] C:/R/library #> #> ──────────────────────────────────────────────────────────────────────────────"},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Using the tidyverse with terra objects: the tidyterra package","text":"tidyterra R (R Core Team 2023) package allows manipulation spatial data objects provided terra package (Hijmans 2023), using verbs packages included tidyverse (Wickham et al. 2019), dplyr (Wickham et al. 2023), tidyr (Wickham, Vaughan, Girlich 2023), tibble (Müller Wickham 2023). addition enables users already familiar tidyverse approach spatial data manipulation analysis easily much faster. Furthermore, tidyterra extends functionality ggplot2 package (Wickham 2016) providing additional geoms stats 1 like geom_spatraster() geom_spatvector(), well carefully chosen scales color palettes specifically designed map production. tidyterra can manipulate following classes terra objects: SpatVector objects, represent vector data points, lines, polygon geometries. SpatRaster objects, represent raster data form grid consisting equally sized rectangles. rectangle can contain one values. first stable version tidyterra included CRAN April 24, 2022, actively used packages (ebvcuve (Quoss et al. 2021), biomod2 (Thuiller et al. 2023), inlabru (Bachl et al. 2019), RCzechia (Lacko 2023) sparrpowR (Buller et al. 2021)) cited academic research publications (Bahlburg et al. (2023), Moraga (2024), Leonardi, Colucci, Manica (2023), Meister et al. (2023)) ever since.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"statement-of-need","dir":"Articles","previous_headings":"","what":"Statement of need","title":"Using the tidyverse with terra objects: the tidyterra package","text":"tidyverse compilation R packages share underlying design philosophy, grammar, data structures. packages within tidyverse widely used R users tidying, transforming, visualizing data. tidyverse designed work tidy data (“every column variable, every row observation, every cell single value”), represented form data frames tibbles. However, possible extend functionality tidyverse packages work new R object classes registering corresponding S3 methods (Wickham 2019). means dplyr::mutate() can adapted work object class foo creating corresponding S3 method mutate.foo(). popular packages designed spatial data handling, sf (Pebesma 2018) stars (Pebesma Bivand 2023), already provide integration tidyverse part infrastructure, terra objects lack integration natively. Although terra offers wide set functions transforming visualizing SpatRaster SpatVector objects, users familiar package need make additional effort learn syntax. may imply additional challenge initial steps field spatial analysis. tidyterra package developed address integration gap. providing corresponding S3 methods, data analysts can apply syntax functions already familiar rectangular data objects provided terra. enables users familiar spatial data analysis approach area easily. addition, tidyterra also offers functions plotting terra objects using ggplot2 syntax. Although packages like rasterVis (Perpiñán Hijmans 2023) ggspatial (Dunnington 2023) already allow representation SpatRaster objects via ggplot2, tidyterra functions provide additional support advanced mapping. support includes integration faceted maps, contours, automatic conversion spatial layers CRS2 via ggplot2::coord_sf(). Furthermore, tidyterra also provides support SpatVector objects, similar native support sf objects ggplot2 package. Lastly, tidyterra provides collection color palettes specifically designed representing spatial phenomena (Lindsay 2018). Additionally, implements cross-blended hypsometric tints described Patterson Jenny (2011).","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"a-note-on-performance","dir":"Articles","previous_headings":"","what":"A note on performance","title":"Using the tidyverse with terra objects: the tidyterra package","text":"development philosophy tidyterra consists adapting terra objects data frame-like structures performing different data transformations, ultimately may impact performance package. manipulating large raster files (.e. 10.000.000 cells), recommended use native terra syntax, specifically designed handling type files. case plotting, default behavior geoms provided resample SpatRaster presents 500.000 cells speed process (terra::plot() ), however upper limit can modified using maxcell parameter geom function. Note also possible, help page function tidyterra references equivalent terra.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"example-of-use","dir":"Articles","previous_headings":"","what":"Example of use","title":"Using the tidyverse with terra objects: the tidyterra package","text":"tidyterra available CRAN, can easily installed using following commands R: latest developing version hosted GitHub can installed using following command R: following example demonstrates manipulate SpatRaster object using dplyr syntax. Additionally, illustrates seamlessly plot SpatRaster object ggplot2 using geom_spatraster() function: Faceted map multi-layer raster file. following example combine common dplyr workflow (mutate() + select()) plot result. case plot contour plot original SpatRaster using geom_spatraster_contour_filled()also includes overlay SpatVector reference: Contour map temperature variation SpatVector overlay","code":"install.packages(\"tidyterra\") remotes::install_github(\"dieghernan/tidyterra\") library(tidyterra) library(tidyverse) # Load all the packages of tidyverse at once library(scales) # Additional library for labels # Temperatures in Castille and Leon (selected months) rastertemp <- terra::rast(system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\" )) # Rename with the tidyverse rastertemp <- rastertemp %>% rename(April = tavg_04, May = tavg_05, June = tavg_06) # Plot with facets ggplot() + geom_spatraster(data = rastertemp) + facet_wrap(~lyr, ncol = 2) + scale_fill_whitebox_c( palette = \"muted\", labels = label_number(suffix = \"º\"), n.breaks = 12, guide = guide_legend(reverse = TRUE) ) + labs( fill = \"\", title = \"Average temperature in Castille and Leon (Spain)\", subtitle = \"Months of April, May and June\" ) # Compute the variation between April and June and apply a different palette incr_temp <- rastertemp %>% mutate(var = June - April) %>% select(Variation = var) # Overlay an SpatVector cyl_vect <- terra::vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\" )) # Contour map with overlay ggplot() + geom_spatraster_contour_filled(data = incr_temp) + geom_spatvector(data = cyl_vect, fill = NA) + scale_fill_whitebox_d(palette = \"bl_yl_rd\") + theme_grey() + labs( fill = \"º Celsius\", title = \"Variation of temperature in Castille and Leon (Spain)\", subtitle = \"Difference between April and June\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"additional-materials","dir":"Articles","previous_headings":"","what":"Additional materials","title":"Using the tidyverse with terra objects: the tidyterra package","text":"package includes extensive documentation available online https://dieghernan.github.io/tidyterra/ including: Details function, including (possible) equivalent terra function, case users prefer include workflows. Working examples use functions creation plots. Additional articles vignettes, well complete demo different color palettes included package (see Palettes).","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/tidyterra.html","id":"acknowledgements","dir":"Articles","previous_headings":"","what":"Acknowledgements","title":"Using the tidyverse with terra objects: the tidyterra package","text":"like thank Robert J. Hijmans advice support adapting methods, well suggestions helped us improve functionalities package. also thankful Dewey Dunnington, Brent Thorne rest contributors ggspatial package, served key reference initial stages development tidyterra. tidyterra also incorporates pieces code adapted ggplot2 computing contours, relies package isoband (Wickham, Wilke, Pedersen 2022) developed Claus O. Wilke.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"welcome-to-tidyterra","dir":"Articles","previous_headings":"","what":"Welcome to {tidyterra}","title":"Welcome to tidyterra","text":"tidyterra package adds common methods tidyverse SpatRaster SpatVectors objects created terra package. also adds specific geom_spat*() functions plotting kind objects ggplot2.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"why-tidyterra","dir":"Articles","previous_headings":"Welcome to {tidyterra}","what":"Why tidyterra?","title":"Welcome to tidyterra","text":"Spat* objects like regular data frames. different type objects, implemented via S4 object system, syntax computation methods, implemented terra package. implementing tidyverse methods objects, specifically dplyr tidyr methods, useR can now work easily Spat* objects, just like (s)tabular data. Note terms performance, terra much optimized working kind objects, recommended also learn bit terra syntax. function tidyterra refers (possible) corresponding equivalent terra.","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"a-note-for-advanced-terra-users","dir":"Articles","previous_headings":"","what":"A note for advanced terra users","title":"Welcome to tidyterra","text":"previously mentioned, tidyterra optimized terms performance. Specially working filter() mutate() methods, can slow. rule thumb, tidyterra can handle objects less 10.000.000 slots information (.e., terra::ncell(a_rast) * terra::nlyr(a_rast) < 10e6).","code":""},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"get-started-with-tidyterra","dir":"Articles","previous_headings":"","what":"Get started with tidyterra","title":"Welcome to tidyterra","text":"Load tidyterra additional libraries tidyverse: Currently, following methods available: Let’s see action:","code":"library(tidyterra) library(dplyr) library(tidyr)"},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"spatrasters","dir":"Articles","previous_headings":"Get started with tidyterra","what":"SpatRasters","title":"Welcome to tidyterra","text":"See example SpatRaster objects: previous example, : Eliminated first layer raster tavg_04. Created new layer newcol difference layers tavg_05 tavg_06. Relocated newcol first layer SpatRaster. Replaced NA cells newcol 3. Renamed newcol difference. process, essential properties SpatRaster (number cells, columns rows, extent, resolution coordinate reference system) modified. methods filter(), slice() drop_na() can modify properties, applied data frame (number rows modified case).","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") temp <- rast(f) temp #> class : SpatRaster #> dimensions : 87, 118, 3 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source : cyl_temp.tif #> names : tavg_04, tavg_05, tavg_06 #> min values : 1.885463, 5.817587, 10.46338 #> max values : 13.283829, 16.740898, 21.11378 mod <- temp %>% select(-1) %>% mutate(newcol = tavg_06 - tavg_05) %>% relocate(newcol, .before = 1) %>% replace_na(list(newcol = 3)) %>% rename(difference = newcol) mod #> class : SpatRaster #> dimensions : 87, 118, 3 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source(s) : memory #> names : difference, tavg_05, tavg_06 #> min values : 2.817647, 5.817587, 10.46338 #> max values : 5.307511, 16.740898, 21.11378"},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"spatvectors","dir":"Articles","previous_headings":"Get started with tidyterra","what":"SpatVectors","title":"Welcome to tidyterra","text":"tidyterra >= 0.4.0 provides support SpatVectors dplyr tidyr methods, possible arrange, group summarise information SpatVectors. case SpatRaster, basic properties geometry CRS preserved.","code":"lux <- system.file(\"ex/lux.shp\", package = \"terra\") v_lux <- vect(lux) v_lux %>% # Create categories mutate(gr = cut(POP / 1000, 5)) %>% group_by(gr) %>% # Summary summarise( n = n(), tot_pop = sum(POP), mean_area = mean(AREA) ) %>% # Arrange arrange(desc(gr)) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 4 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : gr n tot_pop mean_area #> type : #> values : (147,183] 2 3.594e+05 244 #> (40.7,76.1] 1 4.819e+04 185 #> (4.99,40.7] 9 1.944e+05 209.8"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"spatrasters-1","dir":"Articles","previous_headings":"Plotting with ggplot2","what":"SpatRasters","title":"Welcome to tidyterra","text":"tidyterra provides several geom_* SpatRasters. SpatRaster CRS informed (.e. terra::crs(a_rast) != \"\"), geom uses ggplot2::coord_sf(), may also reprojected adjusting coordinates spatial layers: faceted SpatRaster Contour lines plot SpatRaster Contour filled plot SpatRaster tidyterra can also plot RGB SpatRasters add imagery plots: Plotting RGB SpatRaster tidyterra provides selected scales suitable creating hypsometric bathymetric maps: Hypsometric tints","code":"library(ggplot2) # A faceted SpatRaster ggplot() + geom_spatraster(data = temp) + facet_wrap(~lyr) + scale_fill_whitebox_c( palette = \"muted\", na.value = \"white\" ) # Contour lines for a specific layer f_volcano <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") volcano2 <- rast(f_volcano) ggplot() + geom_spatraster(data = volcano2) + geom_spatraster_contour(data = volcano2, breaks = seq(80, 200, 5)) + scale_fill_whitebox_c() + coord_sf(expand = FALSE) + labs(fill = \"elevation\") # Contour filled ggplot() + geom_spatraster_contour_filled(data = volcano2) + scale_fill_whitebox_d(palette = \"atlas\") + labs(fill = \"elevation\") # Read a vector f_v <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- vect(f_v) # Read a tile f_rgb <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") r_rgb <- rast(f_rgb) rgb_plot <- ggplot(v) + geom_spatraster_rgb(data = r_rgb) + geom_spatvector(fill = NA, size = 1) rgb_plot asia <- rast(system.file(\"extdata/asia.tif\", package = \"tidyterra\")) asia #> class : SpatRaster #> dimensions : 164, 306, 1 (nrow, ncol, nlyr) #> resolution : 31836.23, 31847.57 (x, y) #> extent : 7619120, 17361007, -1304745, 3918256 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source : asia.tif #> name : file44bc291153f2 #> min value : -9558.468 #> max value : 5801.927 ggplot() + geom_spatraster(data = asia) + scale_fill_hypso_tint_c( palette = \"gmt_globe\", labels = scales::label_number(), # Further refinements breaks = c(-10000, -5000, 0, 2000, 5000, 8000), guide = guide_colorbar(reverse = TRUE) ) + labs( fill = \"elevation (m)\", title = \"Hypsometric map of Asia\" ) + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"spatvectors-1","dir":"Articles","previous_headings":"Plotting with ggplot2","what":"SpatVectors","title":"Welcome to tidyterra","text":"tidyterra allows plot SpatVectors ggplot2 using geom_spatvector() functions: Plotting SpatVectors underlying implementation take advantage conversion terra::vect()/sf::st_as_sf() use ggplot2::geom_sf() endpoint creating layer. tidyterra can also aggregate SpatVectors convenience: Union SpatVectors Union SpatVector keeping inner borders","code":"lux <- system.file(\"ex/lux.shp\", package = \"terra\") v_lux <- terra::vect(lux) ggplot(v_lux) + geom_spatvector(aes(fill = POP), color = \"white\") + geom_spatvector_text(aes(label = NAME_2), color = \"grey90\") + scale_fill_binned(labels = scales::number_format()) + coord_sf(crs = 3857) # Dissolving v_lux %>% # Create categories mutate(gr = cut(POP / 1000, 5)) %>% group_by(gr) %>% # Summary summarise( n = n(), tot_pop = sum(POP), mean_area = mean(AREA) ) %>% ggplot() + geom_spatvector(aes(fill = tot_pop), color = \"black\") + geom_spatvector_label(aes(label = gr)) + coord_sf(crs = 3857) # Same but keeping internal boundaries v_lux %>% # Create categories mutate(gr = cut(POP / 1000, 5)) %>% group_by(gr) %>% # Summary without dissolving summarise( n = n(), tot_pop = sum(POP), mean_area = mean(AREA), .dissolve = FALSE ) %>% ggplot() + geom_spatvector(aes(fill = tot_pop), color = \"black\") + geom_spatvector_label(aes(label = gr)) + coord_sf(crs = 3857)"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Diego Hernangómez. Author, maintainer, copyright holder. Dewey Dunnington. Contributor. ggspatial code ggplot2 authors. Copyright holder. contour code","code":""},{"path":"https://dieghernan.github.io/tidyterra/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Hernangómez D (2023). “Using tidyverse terra objects: tidyterra package.” Journal Open Source Software, 8(91), 5751. ISSN 2475-9066, doi:10.21105/joss.05751, https://doi.org/10.21105/joss.05751.","code":"@Article{R-tidyterra, title = {Using the {tidyverse} with {terra} objects: the {tidyterra} package}, doi = {10.21105/joss.05751}, author = {Diego Hernangómez}, year = {2023}, url = {https://doi.org/10.21105/joss.05751}, publisher = {The Open Journal}, volume = {8}, number = {91}, pages = {5751}, journal = {Journal of Open Source Software}, issn = {2475-9066}, }"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement diego.hernangomezherrero@gmail.com. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"fixing-typos","dir":"","previous_headings":"","what":"Fixing typos","title":"CONTRIBUTING","text":"Small typos grammatical errors documentation may edited directly using GitHub web interface, long changes made source file. YES: edit roxygen comment .R file R/. : edit .Rd file man/.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"prerequisites","dir":"","previous_headings":"","what":"Prerequisites","title":"CONTRIBUTING","text":"make substantial pull request, always file issue make sure someone team agrees ’s problem. ’ve found bug, create associated issue illustrate bug minimal reprex.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"pull-request-process","dir":"","previous_headings":"","what":"Pull request process","title":"CONTRIBUTING","text":"recommend create Git branch pull request (PR). Look R-CMD-check build status making changes. recommend tidyverse style guide. can use styler package apply styles, please don’t restyle code nothing PR. use roxygen2. use testthat. Contributions test cases included easier accept. user-facing changes, add bullet top NEWS.md current development version header describing changes made followed GitHub username, links relevant issue(s)/PR(s).","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"prefer-to-email","dir":"","previous_headings":"","what":"Prefer to Email?","title":"CONTRIBUTING","text":"Email person listed maintainer DESCRIPTION file repo. Though note private discussions email don’t help others - course email totally warranted ’s sensitive problem kind.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"thanks-for-contributing","dir":"","previous_headings":"","what":"Thanks for contributing!","title":"CONTRIBUTING","text":"contributing guide adapted tidyverse contributing guide available https://raw.githubusercontent.com/r-lib/usethis/master/inst/templates/tidy-contributing.md","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"tidyterra-","dir":"","previous_headings":"","what":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"goal tidyterra provide common methods tidyverse packages objects created terra package: SpatRaster SpatVector. also provides geoms plotting objects ggplot2. Please cite tidyterra : Hernangómez, D., (2023). Using tidyverse terra objects: tidyterra package. Journal Open Source Software, 8(91), 5751, https://doi.org/10.21105/joss.05751. BibTeX entry LaTeX users :","code":"@article{Hernangómez2023, doi = {10.21105/joss.05751}, url = {https://doi.org/10.21105/joss.05751}, year = {2023}, publisher = {The Open Journal}, volume = {8}, number = {91}, pages = {5751}, author = {Diego Hernangómez}, title = {Using the {tidyverse} with {terra} objects: the {tidyterra} package}, journal = {Journal of Open Source Software} }"},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Full manual recent release tidyterra CRAN online: https://dieghernan.github.io/tidyterra/ tidyverse methods implemented tidyterra works differently depending type Spat* object: SpatVector: methods implemented using terra::.data.frame() coercion. Rows correspond geometries columns correspond attributes geometry. SpatRaster: implementation SpatRaster objects differs, since methods applied layers cells. tidyterra overall approach treat layers columns tibble cells rows (.e. select(SpatRaster, 1) select first layer SpatRaster). methods implemented return type object used input, unless expected behavior method return another type object, (example, as_tibble() return tibble). Current methods functions provided tidyterra :","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"exclamation-a-note-on-performance","dir":"","previous_headings":"","what":"❗ A note on performance","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"tidyterra conceived user-friendly wrapper terra using tidyverse methods verbs. approach therefore cost terms performance. heavy user terra need work big raster files, terra much focused terms performance. possible, function tidyterra references equivalent terra. rule thumb raster less 10.000.000 data slots counting cells layers (.e. terra::ncell(your_rast)*terra::nlyr(your_rast) < 10e6) good go tidyterra. plotting rasters, resampling performed automatically (terra::plot() , see help page). can adjust maxcell parameter.","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Install tidyterra CRAN: can install development version tidyterra like : Alternatively, can install tidyterra using r-universe:","code":"install.packages(\"tidyterra\") remotes::install_github(\"dieghernan/tidyterra\") # Enable this universe install.packages(\"tidyterra\", repos = c( \"https://dieghernan.r-universe.dev\", \"https://cloud.r-project.org\" ))"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"spatrasters","dir":"","previous_headings":"Example","what":"SpatRasters","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"basic example shows manipulate plot SpatRaster objects: tidyterra also provide geom plotting RGB SpatRaster tiles ggplot2 tidyterra provides specific scales plotting hypsometric maps ggplot2:","code":"library(tidyterra) library(terra) # Temperatures rastertemp <- rast(system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\")) rastertemp #> class : SpatRaster #> dimensions : 87, 118, 3 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source : cyl_temp.tif #> names : tavg_04, tavg_05, tavg_06 #> min values : 1.885463, 5.817587, 10.46338 #> max values : 13.283829, 16.740898, 21.11378 # Rename rastertemp <- rastertemp %>% rename(April = tavg_04, May = tavg_05, June = tavg_06) # Facet all layers library(ggplot2) ggplot() + geom_spatraster(data = rastertemp) + facet_wrap(~lyr, ncol = 2) + scale_fill_whitebox_c( palette = \"muted\", labels = scales::label_number(suffix = \"º\"), n.breaks = 12, guide = guide_legend(reverse = TRUE) ) + labs( fill = \"\", title = \"Average temperature in Castille and Leon (Spain)\", subtitle = \"Months of April, May and June\" ) # Create maximum differences of two months variation <- rastertemp %>% mutate(diff = June - May) %>% select(variation = diff) # Add also a overlay of a SpatVector prov <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) ggplot(prov) + geom_spatraster(data = variation) + geom_spatvector(fill = NA) + scale_fill_whitebox_c( palette = \"deep\", direction = -1, labels = scales::label_number(suffix = \"º\"), n.breaks = 5 ) + theme_minimal() + coord_sf(crs = 25830) + labs( fill = \"variation\", title = \"Variation of temperature in Castille and Leon (Spain)\", subtitle = \"Average temperatures in June vs. May\" ) rgb_tile <- rast(system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\")) plot <- ggplot(prov) + geom_spatraster_rgb(data = rgb_tile) + geom_spatvector(fill = NA) + theme_light() plot # Recognizes coord_sf() plot + # Change crs and datum (for relabeling graticules) coord_sf(crs = 3857, datum = 3857) asia <- rast(system.file(\"extdata/asia.tif\", package = \"tidyterra\")) terra::plot(asia) ggplot() + geom_spatraster(data = asia) + scale_fill_hypso_tint_c( palette = \"gmt_globe\", labels = scales::label_number(), # Further refinements breaks = c(-10000, -5000, 0, 2000, 5000, 8000), guide = guide_colorbar(reverse = TRUE) ) + labs( fill = \"elevation (m)\", title = \"Hypsometric map of Asia\" ) + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" )"},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"spatvectors","dir":"","previous_headings":"Example","what":"SpatVectors","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"basic example shows manipulate plot SpatVector objects:","code":"vect(system.file(\"ex/lux.shp\", package = \"terra\")) %>% mutate(pop_dens = POP / AREA) %>% glimpse() %>% autoplot(aes(fill = pop_dens)) + scale_fill_whitebox_c(palette = \"pi_y_g\") + labs( fill = \"population per km2\", title = \"Population density of Luxembourg\", subtitle = \"By canton\" ) #> # A SpatVector 12 x 7 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 44' 38.9\" E / 6° 31' 41.71\" E] , [49° 26' 52.11\" N / 50° 10' 53.84\" N]) #> #> $ ID_1 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3 #> $ NAME_1 \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Diekirch\", \"… #> $ ID_2 1, 2, 3, 4, 5, 6, 7, 12, 8, 9, 10, 11 #> $ NAME_2 \"Clervaux\", \"Diekirch\", \"Redange\", \"Vianden\", \"Wiltz\", \"Echte… #> $ AREA 312, 218, 259, 76, 263, 188, 129, 210, 185, 251, 237, 233 #> $ POP 18081, 32543, 18664, 5163, 16735, 18899, 22366, 29828, 48187,… #> $ pop_dens 57.95192, 149.27982, 72.06178, 67.93421, 63.63118, 100.52660,…"},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"i-need-your-feedback","dir":"","previous_headings":"","what":"I need your feedback","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Please leave feedback open issue https://github.com/dieghernan/tidyterra/issues.","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"need-help","dir":"","previous_headings":"","what":"Need help?","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Check FAQs open new issue! can also ask Stack Overflow using tag [tidyterra].","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"acknowledgement","dir":"","previous_headings":"","what":"Acknowledgement","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"tidyterra ggplot2 geoms based ggspatial implementation, Dewey Dunnington ggspatial contributors.","code":""},{"path":"https://dieghernan.github.io/tidyterra/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2022 tidyterra authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Order a SpatVector using column values — arrange.SpatVector","title":"Order a SpatVector using column values — arrange.SpatVector","text":"arrange.SpatVector() orders geometries SpatVector values selected columns.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Order a SpatVector using column values — arrange.SpatVector","text":"","code":"# S3 method for class 'SpatVector' arrange(.data, ..., .by_group = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Order a SpatVector using column values — arrange.SpatVector","text":".data SpatVector created terra::vect(). ... Variables, functions variables. Use desc() sort variable descending order. .by_group TRUE, sort first grouping variable. Applies grouped SpatVector (see group_by.SpatVector()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Order a SpatVector using column values — arrange.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Order a SpatVector using column values — arrange.SpatVector","text":"terra::sort()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Order a SpatVector using column values — arrange.SpatVector","text":"Implementation generic dplyr::arrange() function SpatVector class.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Order a SpatVector using column values — arrange.SpatVector","text":"","code":"library(terra) #> terra 1.8.5 library(dplyr) #> #> Attaching package: 'dplyr' #> The following objects are masked from 'package:terra': #> #> intersect, union #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) # Single variable v %>% arrange(desc(iso2)) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-ZA 49 Zamora #> ES-VA 47 Valladolid #> ES-SO 42 Soria # Two variables v %>% mutate(even = as.double(cpro) %% 2 == 0, ) %>% arrange(desc(even), desc(iso2)) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 4 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name even #> type : #> values : ES-SO 42 Soria TRUE #> ES-SG 40 Segovia TRUE #> ES-P 34 Palencia TRUE # With new variables v %>% mutate(area_geom = terra::expanse(v)) %>% arrange(area_geom) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 4 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name area_geom #> type : #> values : ES-SG 40 Segovia 6.921e+09 #> ES-P 34 Palencia 8.042e+09 #> ES-AV 05 Avila 8.053e+09"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":null,"dir":"Reference","previous_headings":"","what":"Get cell number, row and column from a SpatRaster — as_coordinates","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"as_coordinates() can used obtain position cell SpatRaster matrix.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"","code":"as_coordinates(x, as.raster = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"x SpatRaster object. .raster TRUE, result SpatRaster object three layers indicating position cell (cell number, row column).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"tibble SpatRaster (.raster = TRUE) number rows (cells) number cells x. .raster = TRUE resulting SpatRaster crs, extension resolution x","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) as_coordinates(r) #> # A tibble: 10,266 × 3 #> cellindex rowindex colindex #> #> 1 1 1 1 #> 2 2 1 2 #> 3 3 1 3 #> 4 4 1 4 #> 5 5 1 5 #> 6 6 1 6 #> 7 7 1 7 #> 8 8 1 8 #> 9 9 1 9 #> 10 10 1 10 #> # ℹ 10,256 more rows as_coordinates(r, as.raster = TRUE) #> class : SpatRaster #> dimensions : 87, 118, 3 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source(s) : memory #> names : cellindex, rowindex, colindex #> min values : 1, 1, 1 #> max values : 10266, 87, 118 as_coordinates(r, as.raster = TRUE) %>% plot()"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce a SpatVector to a sf object — as_sf","title":"Coerce a SpatVector to a sf object — as_sf","text":"as_sf() turns SpatVector sf object. wrapper sf::st_as_sf() particularity groups created group_by.SpatVector() preserved.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce a SpatVector to a sf object — as_sf","text":"","code":"as_sf(x, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce a SpatVector to a sf object — as_sf","text":"x SpatVector. ... additional arguments passed sf::st_as_sf().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerce a SpatVector to a sf object — as_sf","text":"sf object object additional tbl_df class, pretty printing method.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce a SpatVector to a sf object — as_sf","text":"","code":"library(terra) f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- terra::vect(f) # This is ungrouped v #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos #> ES-LE 24 Leon is_grouped_spatvector(v) #> [1] FALSE # Get an ungrouped data a_sf <- as_sf(v) dplyr::is_grouped_df(a_sf) #> [1] FALSE # Grouped v$gr <- c(\"C\", \"A\", \"A\", \"B\", \"A\", \"B\", \"B\") v$gr2 <- rep(c(\"F\", \"G\", \"F\"), 3) gr_v <- group_by(v, gr, gr2) gr_v #> class : SpatVector #> geometry : polygons #> dimensions : 9, 5 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name gr gr2 #> type : #> values : ES-AV 05 Avila C F #> ES-BU 09 Burgos A G #> ES-LE 24 Leon A F is_grouped_spatvector(gr_v) #> [1] TRUE group_data(gr_v) #> # A tibble: 5 × 3 #> gr gr2 .rows #> > #> 1 A F [2] #> 2 A G [2] #> 3 B F [3] #> 4 C F [1] #> 5 C G [1] # A sf a_gr_sf <- as_sf(gr_v) dplyr::is_grouped_df(a_gr_sf) #> [1] TRUE group_data(a_gr_sf) #> # A tibble: 5 × 3 #> gr gr2 .rows #> > #> 1 A F [2] #> 2 A G [2] #> 3 B F [3] #> 4 C F [1] #> 5 C G [1]"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce a data frame to SpatRaster — as_spatraster","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"as_spatraster() turns existing data frame tibble SpatRaster. wrapper terra::rast() S4 method signature data.frame.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"","code":"as_spatraster(x, ..., xycols = 1:2, crs = \"\", digits = 6)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"x tibble data frame. ... additional arguments passed terra::rast(). xycols vector integers length 2 determining position columns hold x y coordinates. crs crs several formats (PROJ.4, WKT, EPSG code, ..) spatial object sf terra. includes target coordinate reference system. See pull_crs() Details. digits integer set precision detecting whether points regular grid (low number digits low precision).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"SpatRaster.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"crs provided tibble created method as_tibble.SpatRaster(), crs inferred attr(x, \"crs\").","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"terra::rast() (see S4 method signature data.frame).","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"","code":"library(terra) r <- rast(matrix(1:90, ncol = 3), crs = \"EPSG:3857\") r #> class : SpatRaster #> dimensions : 30, 3, 1 (nrow, ncol, nlyr) #> resolution : 1, 1 (x, y) #> extent : 0, 3, 0, 30 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> name : lyr.1 #> min value : 1 #> max value : 90 # Create tibble as_tbl <- as_tibble(r, xy = TRUE) as_tbl #> # A tibble: 90 × 3 #> x y lyr.1 #> #> 1 0.5 29.5 1 #> 2 1.5 29.5 31 #> 3 2.5 29.5 61 #> 4 0.5 28.5 2 #> 5 1.5 28.5 32 #> 6 2.5 28.5 62 #> 7 0.5 27.5 3 #> 8 1.5 27.5 33 #> 9 2.5 27.5 63 #> 10 0.5 26.5 4 #> # ℹ 80 more rows # From tibble newrast <- as_spatraster(as_tbl, crs = \"EPSG:3857\") newrast #> class : SpatRaster #> dimensions : 30, 3, 1 (nrow, ncol, nlyr) #> resolution : 1, 1 (x, y) #> extent : 0, 3, 0, 30 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> name : lyr.1 #> min value : 1 #> max value : 90"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":null,"dir":"Reference","previous_headings":"","what":"Method for coercing objects to SpatVector — as_spatvector","title":"Method for coercing objects to SpatVector — as_spatvector","text":"as_spatvector() turns existing object SpatVector. wrapper terra::vect() S4 method signature data.frame.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Method for coercing objects to SpatVector — as_spatvector","text":"","code":"as_spatvector(x, ...) # S3 method for class 'data.frame' as_spatvector(x, ..., geom = c(\"lon\", \"lat\"), crs = \"\") # S3 method for class 'sf' as_spatvector(x, ...) # S3 method for class 'sfc' as_spatvector(x, ...) # S3 method for class 'SpatVector' as_spatvector(x, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Method for coercing objects to SpatVector — as_spatvector","text":"x tibble, data frame sf object class sf sfc. ... additional arguments passed terra::vect(). geom character. field name(s) geometry data. Either two names x y coordinates points, single name single column WKT geometries. crs crs several formats (PROJ.4, WKT, EPSG code, ..) spatial object sf terra includes target coordinate reference system. See pull_crs() Details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Method for coercing objects to SpatVector — as_spatvector","text":"SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Method for coercing objects to SpatVector — as_spatvector","text":"function differs terra::vect() following: geometries NA \"\" values removed prior conversion x grouped data frame (see dplyr::group_by()) grouping vars transferred \"grouped\" SpatVector created (see group_by.SpatVector()). crs provided tibble created method as_tibble.SpatVector(), crs inferred attr(x, \"crs\"). Handles correctly conversion EMPTY geometries sf terra.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Method for coercing objects to SpatVector — as_spatvector","text":"terra::vect()","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Method for coercing objects to SpatVector — as_spatvector","text":"","code":"library(terra) v <- vect(matrix(1:80, ncol = 2), crs = \"EPSG:3857\") v$cat <- sample(LETTERS[1:4], size = nrow(v), replace = TRUE) v #> class : SpatVector #> geometry : points #> dimensions : 40, 1 (geometries, attributes) #> extent : 1, 40, 41, 80 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> names : cat #> type : #> values : A #> C #> D # Create tibble as_tbl <- as_tibble(v, geom = \"WKT\") as_tbl #> # A tibble: 40 × 2 #> cat geometry #> #> 1 A POINT (1 41) #> 2 C POINT (2 42) #> 3 D POINT (3 43) #> 4 C POINT (4 44) #> 5 A POINT (5 45) #> 6 B POINT (6 46) #> 7 C POINT (7 47) #> 8 C POINT (8 48) #> 9 C POINT (9 49) #> 10 D POINT (10 50) #> # ℹ 30 more rows # From tibble newvect <- as_spatvector(as_tbl, geom = \"geometry\", crs = \"EPSG:3857\") newvect #> class : SpatVector #> geometry : points #> dimensions : 40, 1 (geometries, attributes) #> extent : 1, 40, 41, 80 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> names : cat #> type : #> values : A #> C #> D"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"as_tibble() methods SpatRaster SpatVector objects.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"","code":"# S3 method for class 'SpatRaster' as_tibble(x, ..., xy = FALSE, na.rm = FALSE, .name_repair = \"unique\") # S3 method for class 'SpatVector' as_tibble(x, ..., geom = NULL, .name_repair = \"unique\")"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"x SpatRaster created terra::rast() SpatVector created terra::vect(). ... Arguments passed terra::.data.frame(). xy logical. TRUE, coordinates raster cell included na.rm logical. TRUE, cells NA value least one layer removed. argument set NA cells NA values layers removed .name_repair Treatment problematic column names: \"minimal\": name repair checks, beyond basic existence. \"unique\": Make sure names unique empty. \"check_unique\": (default value), name repair, check unique. \"universal\": Make names unique syntactic. function: apply custom name repair (e.g., .name_repair = make.names names style base R). purrr-style anonymous function, see rlang::as_function(). geom character NULL. NULL, either \"WKT\" \"HEX\", get geometry included Well-Known-Text hexadecimal notation. x point geometry, can also \"XY\" add coordinates point","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"tibble.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"terra::.data.frame()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"Implementation generic tibble::as_tibble() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"spatraster-and-spatvector","dir":"Reference","previous_headings":"","what":"SpatRaster and SpatVector","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"tibble returned attribute including crs initial object WKT format (see pull_crs()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"about-layer-column-names","dir":"Reference","previous_headings":"","what":"About layer/column names","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"coercing SpatRaster objects data frames, x y names reserved geographic coordinates cell SpatRaster also noted terra allows layers duplicated names. process coercing SpatRaster tibble, tidyterra may rename layers SpatRaster overcoming issue. Specifically, layers may renamed following cases: Layers duplicated names. coercing tibble, xy = TRUE, layers named x y renamed. working tidyverse methods (.e. filter.SpatRaster()), latter happen well. tidyterra display message informing changes names layer. issue happens SpatVector names geometry (geom = c(\"WKT\", \"HEX\")) x, y (geom = \"XY\"). reserved names representing geometry SpatVector (see terra::.data.frame()). geom NULL logic described SpatRaster apply well columns SpatVector.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"","code":"library(terra) # SpatRaster f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) as_tibble(r, na.rm = TRUE) #> # A tibble: 6,522 × 3 #> tavg_04 tavg_05 tavg_06 #> #> 1 3.18 6.79 11.1 #> 2 5.30 8.73 12.7 #> 3 4.59 8.05 12.1 #> 4 6.38 9.72 13.6 #> 5 4.05 7.58 11.8 #> 6 2.90 6.54 10.9 #> 7 5.05 8.49 12.5 #> 8 2.58 6.17 10.5 #> 9 9.30 12.5 15.4 #> 10 9.84 13.0 15.9 #> # ℹ 6,512 more rows as_tibble(r, xy = TRUE) #> # A tibble: 10,266 × 5 #> x y tavg_04 tavg_05 tavg_06 #> #> 1 -610395. 4618746. NA NA NA #> 2 -606513. 4618746. NA NA NA #> 3 -602632. 4618746. NA NA NA #> 4 -598751. 4618746. NA NA NA #> 5 -594870. 4618746. NA NA NA #> 6 -590988. 4618746. NA NA NA #> 7 -587107. 4618746. NA NA NA #> 8 -583226. 4618746. NA NA NA #> 9 -579345. 4618746. NA NA NA #> 10 -575463. 4618746. NA NA NA #> # ℹ 10,256 more rows # SpatVector f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- vect(f) as_tibble(v) #> # A tibble: 9 × 3 #> iso2 cpro name #> #> 1 ES-AV 05 Avila #> 2 ES-BU 09 Burgos #> 3 ES-LE 24 Leon #> 4 ES-P 34 Palencia #> 5 ES-SA 37 Salamanca #> 6 ES-SG 40 Segovia #> 7 ES-SO 42 Soria #> 8 ES-VA 47 Valladolid #> 9 ES-ZA 49 Zamora"},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a complete ggplot for Spat* objects — autoplot.Spat","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"autoplot() uses ggplot2 draw plots ones produced terra::plot()/terra::plotRGB() single command.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"","code":"# S3 method for class 'SpatRaster' autoplot( object, ..., rgb = NULL, use_coltab = NULL, facets = NULL, nrow = NULL, ncol = 2 ) # S3 method for class 'SpatVector' autoplot(object, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"object SpatRaster created terra::rast() SpatVector created terra::vect(). ... arguments passed geom_spatraster(), geom_spatraster_rgb() geom_spatvector(). rgb Logical. plotted RGB image? NULL (default) autoplot.SpatRaster() try guess. use_coltab Logical. plotted corresponding terra::coltab()? NULL (default) autoplot.SpatRaster() try guess. See also scale_fill_coltab(). facets Logical. facets displayed? NULL (default) autoplot.SpatRaster() try guess. nrow, ncol Number rows columns facet.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Implementation ggplot2::autoplot() method.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Implementation generic ggplot2::autoplot() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Uses geom_spatraster() geom_spatraster_rgb().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Uses geom_spatvector(). Labels can placed geom_spatvector_text() geom_spatvector_label().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"","code":"# \\donttest{ file_path <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") library(terra) temp <- rast(file_path) library(ggplot2) autoplot(temp) # With a tile tile <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") %>% rast() autoplot(tile) # With coltabs ctab <- system.file(\"extdata/cyl_era.tif\", package = \"tidyterra\") %>% rast() autoplot(ctab) # With vectors v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) autoplot(v) v %>% autoplot(aes(fill = cpro)) + geom_spatvector_text(aes(label = iso2)) + coord_sf(crs = 25829) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"Bind number SpatVector, data frames sf object column, making wider result. similar .call(cbind, dfs). possible prefer using join combine SpatVector data frames objects. bind_spat_cols() binds rows order appear easy create meaningless results without realizing .","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"","code":"bind_spat_cols( ..., .name_repair = c(\"unique\", \"universal\", \"check_unique\", \"minimal\") )"},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"... Objects combine. first argument SpatVector subsequent arguments can either SpatVector, sf object data frame. Inputs recycled length, matched position. .name_repair One \"unique\", \"universal\", \"check_unique\". See dplyr::bind_cols() Details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"SpatVector corresponding columns. geometry CRS correspond first SpatVector ....","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"cbind() method","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"Implementation dplyr::bind_rows() function SpatVector objects. Note second subsequent arguments ... geometry cbinded, data frame (-ish) columns kept.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"","code":"library(terra) sv <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) df2 <- data.frame(letters = letters[seq_len(nrow(sv))]) # Data frame bind_spat_cols(sv, df2) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 4 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name letters #> type : #> values : ES-AV 05 Avila a #> ES-BU 09 Burgos b #> ES-LE 24 Leon c # Another SpatVector bind_spat_cols(sv[1:2, ], sv[3:4, ]) #> New names: #> • `iso2` -> `iso2...1` #> • `cpro` -> `cpro...2` #> • `name` -> `name...3` #> • `iso2` -> `iso2...4` #> • `cpro` -> `cpro...5` #> • `name` -> `name...6` #> class : SpatVector #> geometry : polygons #> dimensions : 2, 6 (geometries, attributes) #> extent : 2987054, 3296229, 2017622, 2331004 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2...1 cpro...2 name...3 iso2...4 cpro...5 name...6 #> type : #> values : ES-AV 05 Avila ES-LE 24 Leon #> ES-BU 09 Burgos ES-P 34 Palencia # sf objects sfobj <- sf::read_sf(system.file(\"shape/nc.shp\", package = \"sf\")) bind_spat_cols(sv[1:9, ], sfobj[1:9, ]) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 17 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name AREA PERIMETER CNTY_ CNTY_ID NAME FIPS #> type : #> values : ES-AV 05 Avila 0.114 1.442 1825 1825 Ashe 37009 #> ES-BU 09 Burgos 0.061 1.231 1827 1827 Alleghany 37005 #> ES-LE 24 Leon 0.143 1.63 1828 1828 Surry 37171 #> FIPSNO (and 7 more) #> #> 3.701e+04 #> 3.7e+04 #> 3.717e+04 # Mixed end <- bind_spat_cols(sv, sfobj[seq_len(nrow(sv)), 1:2], df2) end #> class : SpatVector #> geometry : polygons #> dimensions : 9, 6 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name AREA PERIMETER letters #> type : #> values : ES-AV 05 Avila 0.114 1.442 a #> ES-BU 09 Burgos 0.061 1.231 b #> ES-LE 24 Leon 0.143 1.63 c glimpse(end) #> # A SpatVector 9 x 6 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\"… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia… #> $ AREA 0.114, 0.061, 0.143, 0.070, 0.153, 0.097, 0.062, 0.091, 0.118 #> $ PERIMETER 1.442, 1.231, 1.630, 2.968, 2.206, 1.670, 1.547, 1.284, 1.421 #> $ letters \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\" # Row sizes must be compatible when column-binding try(bind_spat_cols(sv, sfobj)) #> Error in dplyr::bind_cols(alltibbs, .name_repair = .name_repair) : #> Can't recycle `..1` (size 9) to match `..2` (size 100)."},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"Bind number SpatVector, data frames sf/sfc objects row, making longer result. similar .call(rbind, dfs), output contain columns appear inputs.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"","code":"bind_spat_rows(..., .id = NULL)"},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"... Objects combine. first argument SpatVector subsequent arguments can either SpatVector, sf/sfc object data frame. Columns matched name, missing columns filled NA. .id name optional identifier column. Provide string create output column identifies input. column use names available, otherwise use positions.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"SpatVector type first element ....","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"rbind() method","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"Implementation dplyr::bind_rows() function SpatVector objects. first element ... SpatVector. Subsequent elements may SpatVector, sf/sfc objects data frames: subsequent SpatVector/sf/sfc objects present different CRS first element, elements reprojected CRS first element message. element ... tibble/data frame rows cbinded empty geometries message.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"","code":"library(terra) v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) v1 <- v[1, \"cpro\"] v2 <- v[3:5, c(\"name\", \"iso2\")] # You can supply individual SpatVector as arguments: bind_spat_rows(v1, v2) #> class : SpatVector #> geometry : polygons #> dimensions : 4, 3 (geometries, attributes) #> extent : 2892687, 3180130, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE #> NA Palencia ES-P # When you supply a column name with the `.id` argument, a new # column is created to link each row to its original data frame bind_spat_rows(v1, v2, .id = \"id\") #> class : SpatVector #> geometry : polygons #> dimensions : 4, 4 (geometries, attributes) #> extent : 2892687, 3180130, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : id cpro name iso2 #> type : #> values : 1 05 NA NA #> 2 NA Leon ES-LE #> 2 NA Palencia ES-P # \\donttest{ # Use with sf sfobj <- sf::st_as_sf(v2[1, ]) sfobj #> Simple feature collection with 1 feature and 2 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 2926589 ymin: 2233673 xmax: 3125372 ymax: 2361600 #> Projected CRS: ETRS89-extended / LAEA Europe #> name iso2 geometry #> 1 Leon ES-LE POLYGON ((3049427 2233673, ... bind_spat_rows(v1, sfobj) #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2926589, 3126360, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE # Would reproject with a message on different CRS sfobj_3857 <- as_spatvector(sfobj) %>% project(\"EPSG:3857\") bind_spat_rows(v1, sfobj_3857) #> ! Reprojecting object 2 in `...` since it doesn't have the same CRS than object 1 #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2926589, 3126360, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE # And with data frames with a message data(\"mtcars\") bind_spat_rows(v1, sfobj, mtcars, .id = \"id2\") #> ! Object 3 in `...` is #> The result would present empty geoms #> class : SpatVector #> geometry : polygons #> dimensions : 34, 15 (geometries, attributes) #> extent : -180, 3126360, -90, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : id2 cpro name iso2 mpg cyl disp hp drat wt #> type : #> values : 1 05 NA NA NA NA NA NA NA NA #> 2 NA Leon ES-LE NA NA NA NA NA NA #> 3 NA NA NA 21 6 160 110 3.9 2.62 #> (and 5 more) #> #> #> #> # Use lists bind_spat_rows(list(v1[1, ], sfobj[1:2, ])) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 3 (geometries, attributes) #> extent : -180, 3126360, -90, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE #> NA NA NA # Or named list combined with .id bind_spat_rows(list( SpatVector = v1[1, ], sf = sfobj[1, ], mtcars = mtcars[1, ] ), .id = \"source\") #> ! Object 3 in `...` is #> The result would present empty geoms #> class : SpatVector #> geometry : polygons #> dimensions : 3, 15 (geometries, attributes) #> extent : -180, 3126360, -90, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : source cpro name iso2 mpg cyl disp hp drat wt #> type : #> values : SpatVector 05 NA NA NA NA NA NA NA NA #> sf NA Leon ES-LE NA NA NA NA NA NA #> mtcars NA NA NA 21 6 160 110 3.9 2.62 #> (and 5 more) #> #> #> #> # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":null,"dir":"Reference","previous_headings":"","what":"Compare attributes of two SpatRaster objects — compare_spatrasters","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"Two SpatRaster objects compatible (terms combining layers) crs, extent resolution similar. cases can combine objects simply c(x, y). function compares attributes informing results. See Solving issues section minimal guidance.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"","code":"compare_spatrasters(x, y, digits = 6)"},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"x, y SpatRaster objects digits Integer set precision comparing extent resolution.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"invisible logical TRUE/FALSE indicating SpatRaster objects compatible, plus informative message flagging issues found ().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"terra::identical()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"solving-issues","dir":"Reference","previous_headings":"","what":"Solving issues","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"non-equal crs, try terra::project(). non-equal extent try terra::resample(). non-equal resolution can try terra::resample(), terra::aggregate() terra::disagg().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"","code":"library(terra) x <- rast(matrix(1:90, ncol = 3), crs = \"EPSG:3857\") # Nothing compare_spatrasters(x, x) # Different crs y_nocrs <- x crs(y_nocrs) <- NA compare_spatrasters(x, y_nocrs) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • crs # Different extent compare_spatrasters(x, x[1:10, , drop = FALSE]) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • extent # Different resolution y_newres <- x res(y_newres) <- res(x) / 2 compare_spatrasters(x, y_newres) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • resolution # Everything compare_spatrasters(x, project(x, \"epsg:3035\")) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • crs #> • extent #> • resolution"},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Count the observations in each SpatVector group — count.SpatVector","title":"Count the observations in each SpatVector group — count.SpatVector","text":"count() lets quickly count unique values one variables: df %>% count(, b) roughly equivalent df %>% group_by(, b) %>% summarise(n = n()). count() paired tally(), lower-level helper equivalent df %>% summarise(n = n()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Count the observations in each SpatVector group — count.SpatVector","text":"","code":"# S3 method for class 'SpatVector' count( x, ..., wt = NULL, sort = FALSE, name = NULL, .drop = group_by_drop_default(x), .dissolve = TRUE ) # S3 method for class 'SpatVector' tally(x, wt = NULL, sort = FALSE, name = NULL)"},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Count the observations in each SpatVector group — count.SpatVector","text":"x SpatVector. ... Variables group . wt implemented method sort TRUE, show largest groups top. name name new column output. omitted, default n. already column called n, use nn. column called n nn, 'll use nnn, , adding ns gets new name. .drop Handling factor levels appear data, passed group_by(). count(): FALSE include counts empty groups (.e. levels factors exist data). add_count(): deprecated since actually affect output. .dissolve logical. borders aggregated geometries dissolved?","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Count the observations in each SpatVector group — count.SpatVector","text":"SpatVector object additional attribute.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Count the observations in each SpatVector group — count.SpatVector","text":"terra::aggregate()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Count the observations in each SpatVector group — count.SpatVector","text":"Implementation generic dplyr::count() family functions SpatVector objects. tally() always return disaggregated geometry count() can handle . See also summarise.SpatVector().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Count the observations in each SpatVector group — count.SpatVector","text":"","code":"# \\donttest{ library(terra) f <- system.file(\"ex/lux.shp\", package = \"terra\") p <- vect(f) p %>% count(NAME_1, sort = TRUE) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_1 n #> type : #> values : Diekirch 5 #> Luxembourg 4 #> Grevenmacher 3 p %>% count(NAME_1, sort = TRUE) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_1 n #> type : #> values : Diekirch 5 #> Luxembourg 4 #> Grevenmacher 3 p %>% count(pop = ifelse(POP < 20000, \"A\", \"B\")) #> class : SpatVector #> geometry : polygons #> dimensions : 2, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : pop n #> type : #> values : A 5 #> B 7 # tally() is a lower-level function that assumes you've done the grouping p %>% tally() #> class : SpatVector #> geometry : polygons #> dimensions : 1, 1 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : n #> type : #> values : 12 p %>% group_by(NAME_1) %>% tally() #> class : SpatVector #> geometry : polygons #> dimensions : 3, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_1 n #> type : #> values : Diekirch 5 #> Grevenmacher 3 #> Luxembourg 4 # Dissolve geometries by default library(ggplot2) p %>% count(NAME_1) %>% ggplot() + geom_spatvector(aes(fill = n)) # Opt out p %>% count(NAME_1, .dissolve = FALSE, sort = TRUE) %>% ggplot() + geom_spatvector(aes(fill = n)) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/cross_blended_hypsometric_tints_db.html","id":null,"dir":"Reference","previous_headings":"","what":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","title":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","text":"tibble including color map 4 gradient palettes. palettes includes also definition colors limits terms elevation (meters), can used ggplot2::scale_fill_gradientn().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/cross_blended_hypsometric_tints_db.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","text":"tibble 41 rows 6 columns. following fields: pal Name palette. limit Recommended elevation limit (meters) color. r Value red channel (RGB color mode). g Value green channel (RGB color mode). b Value blue channel (RGB color mode). hex Hex code color.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/cross_blended_hypsometric_tints_db.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","text":"Derived : Patterson, T., & Jenny, B. (2011). Development Rationale Cross-blended Hypsometric Tints. Cartographic Perspectives, (69), 31 - 46. doi:10.14714/CP69.20 .","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/cross_blended_hypsometric_tints_db.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","text":"Patterson & Jenny (2011): recently, role design hypsometric tints come scrutiny. One reason concern people misread elevation colors climate vegetation information. Cross-blended hypsometric tints, introduced 2009, partial solution problem. use variable lowland colors customized match differing natural environments world regions, merge one another.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/cross_blended_hypsometric_tints_db.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Cross-blended hypsometric tints — cross_blended_hypsometric_tints_db","text":"","code":"# \\donttest{ data(\"cross_blended_hypsometric_tints_db\") cross_blended_hypsometric_tints_db #> # A tibble: 41 × 6 #> pal limit r g b hex #> #> 1 arid 0 160 152 141 #A0988D #> 2 arid 50 170 160 150 #AAA096 #> 3 arid 200 180 170 158 #B4AA9E #> 4 arid 600 202 190 174 #CABEAE #> 5 arid 1000 212 201 180 #D4C9B4 #> 6 arid 2000 212 184 163 #D4B8A3 #> 7 arid 3000 212 193 179 #D4C1B3 #> 8 arid 4000 212 207 204 #D4CFCC #> 9 arid 5000 220 220 220 #DCDCDC #> 10 arid 6000 235 235 237 #EBEBED #> # ℹ 31 more rows # Select a palette warm <- cross_blended_hypsometric_tints_db %>% filter(pal == \"warm_humid\") f <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") r <- terra::rast(f) library(ggplot2) p <- ggplot() + geom_spatraster(data = r) + labs(fill = \"elevation\") p + scale_fill_gradientn(colors = warm$hex) # Use with limits p + scale_fill_gradientn( colors = warm$hex, values = scales::rescale(warm$limit), limit = range(warm$limit), na.value = \"lightblue\" ) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"Keep unique/distinct rows geometries SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"","code":"# S3 method for class 'SpatVector' distinct(.data, ..., .keep_all = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":".data SpatVector created terra::vect(). ... Optional variables use determining uniqueness. multiple rows given combination inputs, first row preserved. omitted, use variables data frame. reserved variable name, geometry, remove duplicate geometries. See Methods. .keep_all TRUE, keep variables .data. combination ... distinct, keeps first row values.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"terra::unique()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"Implementation generic dplyr::distinct() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"possible remove duplicate geometries including geometry variable explicitly ... call. See Examples.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/distinct.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Keep distinct/unique rows and geometries of SpatVector objects — distinct.SpatVector","text":"","code":"library(terra) v <- vect(system.file(\"ex/lux.shp\", package = \"terra\")) # Create a vector with dups v <- v[sample(seq_len(nrow(v)), 100, replace = TRUE), ] v$gr <- sample(LETTERS[1:3], 100, replace = TRUE) # All duplicates ex1 <- distinct(v) ex1 #> class : SpatVector #> geometry : polygons #> dimensions : 34, 7 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : ID_1 NAME_1 ID_2 NAME_2 AREA POP gr #> type : #> values : 1 Diekirch 5 Wiltz 263 1.674e+04 A #> 2 Grevenmacher 6 Echternach 188 1.89e+04 C #> 3 Luxembourg 8 Capellen 185 4.819e+04 A nrow(ex1) #> [1] 34 # Duplicates by NAME_1 ex2 <- distinct(v, gr) ex2 #> class : SpatVector #> geometry : polygons #> dimensions : 3, 1 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.72324, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : gr #> type : #> values : A #> C #> B nrow(ex2) #> [1] 3 # Same but keeping all cols ex2b <- distinct(v, gr, .keep_all = TRUE) ex2b #> class : SpatVector #> geometry : polygons #> dimensions : 3, 7 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.72324, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : gr ID_1 NAME_1 ID_2 NAME_2 AREA POP #> type : #> values : A 1 Diekirch 5 Wiltz 263 1.674e+04 #> C 2 Grevenmacher 6 Echternach 188 1.89e+04 #> B 1 Diekirch 1 Clervaux 312 1.808e+04 nrow(ex2b) #> [1] 3 # Unique geometries ex3 <- distinct(v, geometry) ex3 #> class : SpatVector #> geometry : polygons #> dimensions : 12, 0 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) nrow(ex3) #> [1] 12 # Same as terra::unique() terra::unique(ex3) #> class : SpatVector #> geometry : polygons #> dimensions : 12, 0 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) # Unique keeping info distinct(v, geometry, .keep_all = TRUE) #> class : SpatVector #> geometry : polygons #> dimensions : 12, 7 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : ID_1 NAME_1 ID_2 NAME_2 AREA POP gr #> type : #> values : 1 Diekirch 5 Wiltz 263 1.674e+04 A #> 2 Grevenmacher 6 Echternach 188 1.89e+04 C #> 3 Luxembourg 8 Capellen 185 4.819e+04 A"},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"SpatVector: drop_na() method drops geometries attribute specified ... contains missing value. SpatRaster: drop_na() method drops cells layer specified ... contains missing value.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"","code":"# S3 method for class 'SpatVector' drop_na(data, ...) # S3 method for class 'SpatRaster' drop_na(data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"data SpatVector created terra::vect() SpatRaster terra::rast(). ... Attributes inspect missing values. empty, attributes used.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"Spat* object class data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"terra::trim()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"Implementation generic tidyr::drop_na() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"implementation method performed -attribute basis, meaning NAs assessed attributes (columns) vector (rows). result SpatVector potentially less geometries input.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"Actual implementation drop_na().SpatRaster can understood masking method based values layers (see terra::mask()). SpatRaster layers considered columns SpatRaster cells rows, rows (cells) NA value layer get NA value. possible also mask cells (rows) based values specific layers (columns). drop_na() effectively remove outer cells NA (see terra::trim()), extent resulting object may differ extent input (see terra::resample() info). Check Examples better understanding method.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"feedback-needed-","dir":"Reference","previous_headings":"","what":"Feedback needed!","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"Visit https://github.com/dieghernan/tidyterra/issues. implementation method SpatRaster may change future.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/drop_na.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Drop attributes of Spat* objects containing missing values — drop_na.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- terra::vect(f) # Add NAs v <- v %>% mutate(iso2 = ifelse(cpro <= \"09\", NA, cpro)) # Init plot(v, col = \"red\") # Mask with lyr.1 v %>% drop_na(iso2) %>% plot(col = \"red\") # SpatRaster method # \\donttest{ r <- rast( crs = \"EPSG:3857\", extent = c(0, 10, 0, 10), nlyr = 3, resolution = c(2.5, 2.5) ) terra::values(r) <- seq_len(ncell(r) * nlyr(r)) # Add NAs r[r > 13 & r < 22 | r > 31 & r < 45] <- NA # Init plot(r, nc = 3) # Mask with lyr.1 r %>% drop_na(lyr.1) %>% plot(nc = 3) # Mask with lyr.2 r %>% drop_na(lyr.2) %>% plot(nc = 3) # Mask with lyr.3 r %>% drop_na(lyr.3) %>% plot(nc = 3) # Auto-mask all layers r %>% drop_na() %>% plot(nc = 3) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"Fills missing values selected columns using next previous entry. useful common output format values repeated, recorded change.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"","code":"# S3 method for class 'SpatVector' fill(data, ..., .direction = c(\"down\", \"up\", \"downup\", \"updown\"))"},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"data SpatVector. ... Columns fill. .direction Direction fill missing values. Currently either \"\" (default), \"\", \"downup\" (.e. first ) \"updown\" (first ).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"Implementation generic tidyr::fill() function SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"grouped-spatvector","dir":"Reference","previous_headings":"","what":"Grouped SpatVector","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"grouped SpatVector created group_by.SpatVector(), fill() applied within group, meaning fill across group boundaries.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/fill.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fill in missing values with previous or next value on a SpatVector — fill.SpatVector","text":"","code":"library(dplyr) lux <- terra::vect(system.file(\"ex/lux.shp\", package = \"terra\")) # Leave some blanks for demo purporses lux_blnk <- lux %>% mutate(NAME_1 = if_else(NAME_1 != NAME_2, NA, NAME_2)) as_tibble(lux_blnk) #> # A tibble: 12 × 6 #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 NA 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 NA 3 Redange 259 18664 #> 4 1 NA 4 Vianden 76 5163 #> 5 1 NA 5 Wiltz 263 16735 #> 6 2 NA 6 Echternach 188 18899 #> 7 2 NA 7 Remich 129 22366 #> 8 2 Grevenmacher 12 Grevenmacher 210 29828 #> 9 3 NA 8 Capellen 185 48187 #> 10 3 NA 9 Esch-sur-Alzette 251 176820 #> 11 3 Luxembourg 10 Luxembourg 237 182607 #> 12 3 NA 11 Mersch 233 32112 # `fill()` defaults to replacing missing data from top to bottom lux_blnk %>% fill(NAME_1) %>% as_tibble() #> # A tibble: 12 × 6 #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 NA 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 Diekirch 3 Redange 259 18664 #> 4 1 Diekirch 4 Vianden 76 5163 #> 5 1 Diekirch 5 Wiltz 263 16735 #> 6 2 Diekirch 6 Echternach 188 18899 #> 7 2 Diekirch 7 Remich 129 22366 #> 8 2 Grevenmacher 12 Grevenmacher 210 29828 #> 9 3 Grevenmacher 8 Capellen 185 48187 #> 10 3 Grevenmacher 9 Esch-sur-Alzette 251 176820 #> 11 3 Luxembourg 10 Luxembourg 237 182607 #> 12 3 Luxembourg 11 Mersch 233 32112 # direction = \"up\" lux_blnk %>% fill(NAME_1, .direction = \"up\") %>% as_tibble() #> # A tibble: 12 × 6 #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 Diekirch 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 Grevenmacher 3 Redange 259 18664 #> 4 1 Grevenmacher 4 Vianden 76 5163 #> 5 1 Grevenmacher 5 Wiltz 263 16735 #> 6 2 Grevenmacher 6 Echternach 188 18899 #> 7 2 Grevenmacher 7 Remich 129 22366 #> 8 2 Grevenmacher 12 Grevenmacher 210 29828 #> 9 3 Luxembourg 8 Capellen 185 48187 #> 10 3 Luxembourg 9 Esch-sur-Alzette 251 176820 #> 11 3 Luxembourg 10 Luxembourg 237 182607 #> 12 3 NA 11 Mersch 233 32112 # Grouping and downup - will restore the initial state lux_blnk %>% group_by(ID_1) %>% fill(NAME_1, .direction = \"downup\") %>% as_tibble() #> # A tibble: 12 × 6 #> # Groups: ID_1 [3] #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 Diekirch 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 Diekirch 3 Redange 259 18664 #> 4 1 Diekirch 4 Vianden 76 5163 #> 5 1 Diekirch 5 Wiltz 263 16735 #> 6 2 Grevenmacher 6 Echternach 188 18899 #> 7 2 Grevenmacher 7 Remich 129 22366 #> 8 2 Grevenmacher 12 Grevenmacher 210 29828 #> 9 3 Luxembourg 8 Capellen 185 48187 #> 10 3 Luxembourg 9 Esch-sur-Alzette 251 176820 #> 11 3 Luxembourg 10 Luxembourg 237 182607 #> 12 3 Luxembourg 11 Mersch 233 32112"},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Filtering joins for SpatVector objects — filter-joins.SpatVector","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"Filtering joins filter rows x based presence absence matches y: semi_join() return rows x match y. anti_join() return rows x without match y. See dplyr::semi_join() details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"","code":"# S3 method for class 'SpatVector' semi_join(x, y, by = NULL, copy = FALSE, ...) # S3 method for class 'SpatVector' anti_join(x, y, by = NULL, copy = FALSE, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"x SpatVector created terra::vect(). y data frame object coercible data frame. SpatVector sf object provided return error (see terra::intersect() performing spatial joins). join specification created join_by(), character vector variables join . NULL, default, *_join() perform natural join, using variables common across x y. message lists variables can check correct; suppress message supplying explicitly. join different variables x y, use join_by() specification. example, join_by(== b) match x$y$b. join multiple variables, use join_by() specification multiple expressions. example, join_by(== b, c == d) match x$y$b x$c y$d. column names x y, can shorten listing variable names, like join_by(, c). join_by() can also used perform inequality, rolling, overlap joins. See documentation ?join_by details types joins. simple equality joins, can alternatively specify character vector variable names join . example, = c(\"\", \"b\") joins x$y$x$b y$b. variable names differ x y, use named character vector like = c(\"x_a\" = \"y_a\", \"x_b\" = \"y_b\"). perform cross-join, generating combinations x y, see cross_join(). copy x y data source, copy TRUE, y copied src x. allows join tables across srcs, potentially expensive operation must opt . ... parameters passed onto methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"terra::merge()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"Implementation generic dplyr::semi_join() family","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"geometry column sticky behavior. means result always geometry x records matches join conditions.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/filter-joins.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Filtering joins for SpatVector objects — filter-joins.SpatVector","text":"","code":"library(terra) library(ggplot2) # Vector v <- terra::vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) # A data frame df <- data.frame( cpro = sprintf(\"%02d\", 1:10), x = runif(10), y = runif(10), letter = rep_len(LETTERS[1:3], length.out = 10) ) v #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos #> ES-LE 24 Leon # Semi join semi <- v %>% semi_join(df) #> Joining with `by = join_by(cpro)` semi #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2987054, 3296229, 2017622, 2331004 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos autoplot(semi, aes(fill = iso2)) + ggtitle(\"Semi Join\") # Anti join anti <- v %>% anti_join(df) #> Joining with `by = join_by(cpro)` anti #> class : SpatVector #> geometry : polygons #> dimensions : 7, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2049224, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-LE 24 Leon #> ES-P 34 Palencia #> ES-SA 37 Salamanca autoplot(anti, aes(fill = iso2)) + ggtitle(\"Anti Join\")"},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Subset cells/geometries of Spat* objects — filter.Spat","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"filter() function used subset Spat* objects, retaining cells/geometries satisfy conditions. retained, cell/geometry must produce value TRUE conditions. possible filter SpatRaster geographic coordinates. need use filter(.data, x > 42). Note x y reserved names terra, since refer geographic coordinates layer. See Examples section layer names as_tibble.Spat().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"","code":"# S3 method for class 'SpatRaster' filter(.data, ..., .preserve = FALSE, .keep_extent = TRUE) # S3 method for class 'SpatVector' filter(.data, ..., .preserve = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... Expressions return logical value, defined terms layers/attributes .data. multiple expressions included, combined & operator. cells/geometries conditions evaluate TRUE kept. See Methods. .preserve Ignored Spat* objects. .keep_extent extent resulting SpatRaster kept? FALSE, terra::trim() called extent result may different extent output. See also drop_na.SpatRaster().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"Implementation generic dplyr::filter() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"Cells fulfill conditions ... returned value NA. multi-layer SpatRaster NA propagated across layers. .keep_extent = TRUE returning SpatRaster crs, extent, resolution hence number cells .data. .keep_extent = FALSE outer NA cells trimmed terra::trim(), extent number cells may differ. output present case crs resolution .data. x y variables (.e. longitude latitude SpatRaster) also available internally filtering. See Examples.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"result SpatVector geometries produce value TRUE conditions.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/filter.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Subset cells/geometries of Spat* objects — filter.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) %>% select(tavg_04) plot(r) # Filter temps r_f <- r %>% filter(tavg_04 > 11.5) # Extent is kept plot(r_f) # Filter temps and extent r_f2 <- r %>% filter(tavg_04 > 11.5, .keep_extent = FALSE) # Extent has changed plot(r_f2) # Filter by geographic coordinates r2 <- project(r, \"epsg:4326\") r2 %>% plot() r2 %>% filter( x > -4, x < -2, y > 42 ) %>% plot()"},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Fortify Spat* Objects — fortify.Spat","title":"Fortify Spat* Objects — fortify.Spat","text":"Fortify SpatRaster SpatVector objects data frames. provide native compatibility ggplot2::ggplot().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fortify Spat* Objects — fortify.Spat","text":"","code":"# S3 method for class 'SpatRaster' fortify( model, data, ..., .name_repair = \"unique\", maxcell = terra::ncell(model) * 1.1, pivot = FALSE ) # S3 method for class 'SpatVector' fortify(model, data, ...) # S3 method for class 'SpatGraticule' fortify(model, data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fortify Spat* Objects — fortify.Spat","text":"model SpatRaster created terra::rast() SpatVector created terra::vect(). data used method. ... arguments passed layer()'s params argument. arguments broadly fall one 4 categories . Notably, arguments position argument, aesthetics required can passed .... Unknown arguments part 4 categories ignored. Static aesthetics mapped scale, fixed value apply layer whole. example, colour = \"red\" linewidth = 3. geom's documentation Aesthetics section lists available options. 'required' aesthetics passed params. Please note passing unmapped aesthetics vectors technically possible, order required length guaranteed parallel input data. constructing layer using stat_*() function, ... argument can used pass parameters geom part layer. example stat_density(geom = \"area\", outline.type = \"\"). geom's documentation lists parameters can accept. Inversely, constructing layer using geom_*() function, ... argument can used pass parameters stat part layer. example geom_area(stat = \"density\", adjust = 0.5). stat's documentation lists parameters can accept. key_glyph argument layer() may also passed .... can one functions described key glyphs, change display layer legend. .name_repair Treatment problematic column names: \"minimal\": name repair checks, beyond basic existence. \"unique\": Make sure names unique empty. \"check_unique\": (default value), name repair, check unique. \"universal\": Make names unique syntactic. function: apply custom name repair (e.g., .name_repair = make.names names style base R). purrr-style anonymous function, see rlang::as_function(). maxcell positive integer. Maximum number cells use plot. pivot Logical. TRUE SpatRaster fortified long format. FALSE (default) fortified data frame column layer. See Details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fortify Spat* Objects — fortify.Spat","text":"fortify.SpatVector() returns sf object fortify.SpatRaster() returns tibble. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Fortify Spat* Objects — fortify.Spat","text":"Implementation generic ggplot2::fortify() method.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Fortify Spat* Objects — fortify.Spat","text":"Return tibble can used ggplot2::geom_* like ggplot2::geom_point(), ggplot2::geom_raster(), etc. resulting tibble includes coordinates columns x, y. values layer included additional columns named per name layer SpatRaster. CRS SpatRaster can retrieved attr(fortifiedSpatRaster, \"crs\"). possible convert fortified object onto SpatRaster as_spatraster(). pivot = TRUE SpatRaster fortified \"long\" format (see tidyr::pivot_longer()). fortified object following columns: x,y: Coordinates (center) cell corresponding CRS. lyr: Indicating name SpatRaster layer value. value: value SpatRaster corresponding lyr. option may useful using several geom_* faceting, see Examples.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"spatvector-and-spatgraticule","dir":"Reference","previous_headings":"","what":"SpatVector and SpatGraticule","title":"Fortify Spat* Objects — fortify.Spat","text":"Return sf object can used ggplot2::geom_sf().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/fortify.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fortify Spat* Objects — fortify.Spat","text":"","code":"# \\donttest{ # Get a SpatRaster r <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") %>% terra::rast() %>% terra::project(\"EPSG:4326\") fortified <- ggplot2::fortify(r) fortified #> # A tibble: 23,166 × 3 #> x y elevation #> #> 1 175. -36.9 NA #> 2 175. -36.9 NA #> 3 175. -36.9 NA #> 4 175. -36.9 NA #> 5 175. -36.9 NA #> 6 175. -36.9 NA #> 7 175. -36.9 NA #> 8 175. -36.9 NA #> 9 175. -36.9 NA #> 10 175. -36.9 NA #> # ℹ 23,156 more rows # The crs is an attribute of the fortified SpatRaster attr(fortified, \"crs\") #> [1] \"GEOGCRS[\\\"WGS 84\\\",\\n ENSEMBLE[\\\"World Geodetic System 1984 ensemble\\\",\\n MEMBER[\\\"World Geodetic System 1984 (Transit)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G730)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G873)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G1150)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G1674)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G1762)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G2139)\\\"],\\n MEMBER[\\\"World Geodetic System 1984 (G2296)\\\"],\\n ELLIPSOID[\\\"WGS 84\\\",6378137,298.257223563,\\n LENGTHUNIT[\\\"metre\\\",1]],\\n ENSEMBLEACCURACY[2.0]],\\n PRIMEM[\\\"Greenwich\\\",0,\\n ANGLEUNIT[\\\"degree\\\",0.0174532925199433]],\\n CS[ellipsoidal,2],\\n AXIS[\\\"geodetic latitude (Lat)\\\",north,\\n ORDER[1],\\n ANGLEUNIT[\\\"degree\\\",0.0174532925199433]],\\n AXIS[\\\"geodetic longitude (Lon)\\\",east,\\n ORDER[2],\\n ANGLEUNIT[\\\"degree\\\",0.0174532925199433]],\\n USAGE[\\n SCOPE[\\\"Horizontal component of 3D system.\\\"],\\n AREA[\\\"World.\\\"],\\n BBOX[-90,-180,90,180]],\\n ID[\\\"EPSG\\\",4326]]\" # Back to a SpatRaster with as_spatraster(fortified) #> class : SpatRaster #> dimensions : 162, 143, 1 (nrow, ncol, nlyr) #> resolution : 4.916776e-05, 4.916772e-05 (x, y) #> extent : 174.7611, 174.7682, -36.87992, -36.87195 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> source(s) : memory #> name : elevation #> min value : 76.56599 #> max value : 195.50436 # You can now use a SpatRaster with any geom library(ggplot2) ggplot(r) + geom_histogram(aes(x = elevation), bins = 20, fill = \"lightblue\", color = \"black\" ) #> Warning: Removed 975 rows containing non-finite outside the scale range (`stat_bin()`). # ... and other packages # Use metR with facets library(metR) temp <- terra::rast(system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\" )) brks <- seq(0, 21, 3) # Fix breaks! # Pivot option for faceting ggplot(temp, aes(x, y), pivot = TRUE) + # tidyterra, don't inherit aes geom_spatraster_contour_filled( data = temp, inherit.aes = FALSE, breaks = brks ) + # metR geom_contour_tanaka(aes(z = value), breaks = brks) + facet_wrap(~lyr, nrow = 1) + scale_fill_whitebox_d(palette = \"muted\") + theme_minimal() + labs( title = \"tidyterra + metR\", subtitle = \"Facets\", fill = \"temp (°C)\", x = \"\", y = \"\" ) # Create a SpatVector extfile <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") cyl <- terra::vect(extfile) cyl #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos #> ES-LE 24 Leon # To sf ggplot2::fortify(cyl) #> Simple feature collection with 9 features and 3 fields #> Geometry type: GEOMETRY #> Dimension: XY #> Bounding box: xmin: 2892687 ymin: 2017622 xmax: 3341372 ymax: 2361600 #> Projected CRS: ETRS89-extended / LAEA Europe #> # A tibble: 9 × 4 #> iso2 cpro name geometry #> * #> 1 ES-AV 05 Avila POLYGON ((3126360 2066778, 3125074 2065007, 3124303 20… #> 2 ES-BU 09 Burgos MULTIPOLYGON (((3276731 2262326, 3275910 2265723, 3270… #> 3 ES-LE 24 Leon POLYGON ((3049427 2233673, 3049069 2234201, 3047819 22… #> 4 ES-P 34 Palencia MULTIPOLYGON (((3175411 2291868, 3175606 2293658, 3177… #> 5 ES-SA 37 Salamanca POLYGON ((3042661 2138939, 3043434 2140279, 3046345 21… #> 6 ES-SG 40 Segovia POLYGON ((3126360 2066778, 3124037 2067928, 3118421 20… #> 7 ES-SO 42 Soria POLYGON ((3194084 2154251, 3194362 2156613, 3195482 21… #> 8 ES-VA 47 Valladolid MULTIPOLYGON (((3158120 2161552, 3155455 2155198, 3149… #> 9 ES-ZA 49 Zamora POLYGON ((3042661 2138939, 3040851 2133391, 3038188 21… # Now you can use geom_sf() straight away thanks to fortify::SpatVector() library(ggplot2) ggplot(cyl) + geom_sf() # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":null,"dir":"Reference","previous_headings":"","what":"Visualise SpatRaster objects — geom_spatraster","title":"Visualise SpatRaster objects — geom_spatraster","text":"geom used visualise SpatRaster objects (see terra::rast()). geom designed visualise object layers, terra::plot() . plotting SpatRaster objects map tiles (.e. RGB SpatRaster), use geom_spatraster_rgb(). underlying implementation based ggplot2::geom_raster(). stat_spatraster() provided complementary function, geom can modified.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Visualise SpatRaster objects — geom_spatraster","text":"","code":"geom_spatraster( mapping = aes(), data, na.rm = TRUE, show.legend = NA, inherit.aes = FALSE, interpolate = FALSE, maxcell = 5e+05, use_coltab = TRUE, ... ) stat_spatraster( mapping = aes(), data, geom = \"raster\", na.rm = TRUE, show.legend = NA, inherit.aes = FALSE, maxcell = 5e+05, ... )"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Visualise SpatRaster objects — geom_spatraster","text":"Based layer_spatial() implementation ggspatial package. Thanks Dewey Dunnington ggspatial contributors.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Visualise SpatRaster objects — geom_spatraster","text":"mapping Set aesthetic mappings created ggplot2::aes(). See Aesthetics specially use fill aesthetic. data SpatRaster object. na.rm TRUE, default, missing values silently removed. FALSE, missing values removed warning. show.legend logical. layer included legends? NA, default, includes aesthetics mapped. FALSE never includes, TRUE always includes. can also named logical vector finely select aesthetics display. inherit.aes FALSE, overrides default aesthetics, rather combining . interpolate TRUE interpolate linearly, FALSE (default) interpolate. maxcell positive integer. Maximum number cells use plot. use_coltab Logical. applicable SpatRaster objects associated coltab. coltab used plot? See also scale_fill_coltab(). ... arguments passed layer()'s params argument. arguments broadly fall one 4 categories . Notably, arguments position argument, aesthetics required can passed .... Unknown arguments part 4 categories ignored. Static aesthetics mapped scale, fixed value apply layer whole. example, colour = \"red\" linewidth = 3. geom's documentation Aesthetics section lists available options. 'required' aesthetics passed params. Please note passing unmapped aesthetics vectors technically possible, order required length guaranteed parallel input data. constructing layer using stat_*() function, ... argument can used pass parameters geom part layer. example stat_density(geom = \"area\", outline.type = \"\"). geom's documentation lists parameters can accept. Inversely, constructing layer using geom_*() function, ... argument can used pass parameters stat part layer. example geom_area(stat = \"density\", adjust = 0.5). stat's documentation lists parameters can accept. key_glyph argument layer() may also passed .... can one functions described key glyphs, change display layer legend. geom geometric object use display data. Recommended geom SpatRaster \"raster\" (default), \"point\",\"text\" \"label\".","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Visualise SpatRaster objects — geom_spatraster","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Visualise SpatRaster objects — geom_spatraster","text":"terra::plot()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"coords","dir":"Reference","previous_headings":"","what":"Coords","title":"Visualise SpatRaster objects — geom_spatraster","text":"SpatRaster present crs (.e., terra::crs(rast) == \"\") geom make assumption scales. SpatRaster crs, geom uses ggplot2::coord_sf() adjust scales. means also SpatRaster may reprojected.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"aesthetics","dir":"Reference","previous_headings":"","what":"Aesthetics","title":"Visualise SpatRaster objects — geom_spatraster","text":"geom_spatraster() understands following aesthetics: fill alpha fill provided, geom_spatraster() creates ggplot2 layer layers SpatRaster object. Use facet_wrap(~lyr) display properly SpatRaster layers. fill used, contain name one layer present SpatRaster (.e. geom_spatraster(data = rast, aes(fill = )). Names layers can retrieved using names(rast). Using geom_spatraster(..., mapping = aes(fill = NULL)) geom_spatraster(..., fill = ) create layer mapped fill aesthetic. fill can use computed variables. alpha use computed variable. See section Computed variables.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"stat-spatraster-","dir":"Reference","previous_headings":"","what":"stat_spatraster()","title":"Visualise SpatRaster objects — geom_spatraster","text":"stat_spatraster() understands aesthetics geom_spatraster() using geom = \"raster\" (default): fill alpha geom = \"raster\" fill parameter behave geom_spatraster(). another geom used stat_spatraster() understand aesthetics required geom aes(fill = ) applicable. Note also mapping aesthetics x y provided default, user need add aesthetics aes(). cases aesthetics mapped using computed variables. See section Computed variables Examples.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"facets","dir":"Reference","previous_headings":"","what":"Facets","title":"Visualise SpatRaster objects — geom_spatraster","text":"can use facet_wrap(~lyr) creating faceted plot layer SpatRaster object. See ggplot2::facet_wrap() details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"computed-variables","dir":"Reference","previous_headings":"","what":"Computed variables","title":"Visualise SpatRaster objects — geom_spatraster","text":"geom computes internally variables available use aesthetics, using (example) aes(alpha = after_stat(value)) (see ggplot2::after_stat()). after_stat(value): Values SpatRaster. after_stat(lyr): Name layer.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Visualise SpatRaster objects — geom_spatraster","text":"","code":"# \\donttest{ # Avg temperature on spring in Castille and Leon (Spain) file_path <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") library(terra) temp_rast <- rast(file_path) library(ggplot2) # Display a single layer names(temp_rast) #> [1] \"tavg_04\" \"tavg_05\" \"tavg_06\" ggplot() + geom_spatraster(data = temp_rast, aes(fill = tavg_04)) + # You can use coord_sf coord_sf(crs = 3857) + scale_fill_grass_c(palette = \"celsius\") # Display facets ggplot() + geom_spatraster(data = temp_rast) + facet_wrap(~lyr, ncol = 2) + scale_fill_grass_b(palette = \"celsius\", breaks = seq(0, 20, 2.5)) # Non spatial rasters no_crs <- rast(crs = NA, extent = c(0, 100, 0, 100), nlyr = 1) values(no_crs) <- seq_len(ncell(no_crs)) ggplot() + geom_spatraster(data = no_crs) # Downsample ggplot() + geom_spatraster(data = no_crs, maxcell = 25) #> resampled to 32 cells. # } # \\donttest{ # Using stat_spatraster # Default ggplot() + stat_spatraster(data = temp_rast) + facet_wrap(~lyr) # Using points ggplot() + stat_spatraster( data = temp_rast, aes(color = after_stat(value)), geom = \"point\", maxcell = 250 ) + scale_colour_viridis_c(na.value = \"transparent\") + facet_wrap(~lyr) #> resampled to 266 cells. # Using points and labels r_single <- temp_rast %>% select(1) ggplot() + stat_spatraster( data = r_single, aes(color = after_stat(value)), geom = \"point\", maxcell = 2000 ) + stat_spatraster( data = r_single, aes(label = after_stat(round(value, 2))), geom = \"label\", alpha = 0.85, maxcell = 20 ) + scale_colour_viridis_c(na.value = \"transparent\") #> resampled to 2067 cells. #> resampled to 24 cells. # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":null,"dir":"Reference","previous_headings":"","what":"Visualise SpatRaster objects as images — geom_spatraster_rgb","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"geom used visualise SpatRaster objects (see terra::rast()) RGB images. layers combined represent red, green blue channel. plotting SpatRaster objects layer values use geom_spatraster(). underlying implementation based ggplot2::geom_raster().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"","code":"geom_spatraster_rgb( mapping = aes(), data, interpolate = TRUE, r = 1, g = 2, b = 3, alpha = 1, maxcell = 5e+05, max_col_value = 255, ..., stretch = NULL, zlim = NULL )"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"Based layer_spatial() implementation ggspatial package. Thanks Dewey Dunnington ggspatial contributors.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"mapping Ignored. data SpatRaster object. interpolate TRUE interpolate linearly, FALSE (default) interpolate. r, g, b Integer representing number layer data considered red (r), green (g) blue (b) channel. alpha alpha transparency, number [0,1], see argument alpha hsv. maxcell positive integer. Maximum number cells use plot. max_col_value Number giving maximum color values range. 255 (default), result computed efficiently. See grDevices::rgb(). ... arguments passed layer()'s params argument. arguments broadly fall one 4 categories . Notably, arguments position argument, aesthetics required can passed .... Unknown arguments part 4 categories ignored. Static aesthetics mapped scale, fixed value apply layer whole. example, colour = \"red\" linewidth = 3. geom's documentation Aesthetics section lists available options. 'required' aesthetics passed params. Please note passing unmapped aesthetics vectors technically possible, order required length guaranteed parallel input data. constructing layer using stat_*() function, ... argument can used pass parameters geom part layer. example stat_density(geom = \"area\", outline.type = \"\"). geom's documentation lists parameters can accept. Inversely, constructing layer using geom_*() function, ... argument can used pass parameters stat part layer. example geom_area(stat = \"density\", adjust = 0.5). stat's documentation lists parameters can accept. key_glyph argument layer() may also passed .... can one functions described key glyphs, change display layer legend. stretch character. Option stretch values increase contrast: \"lin\" (linear) \"hist\" (histogram). linear stretch uses stretch arguments minq=0.02 maxq=0.98 zlim numeric vector length 2. Range values plot (optional). set, stretch=\"lin\" used, values stretched within range zlim. allows creating consistent coloring SpatRasters different cell-value ranges, even stretching colors improved contrast","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"terra::plotRGB()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"aesthetics","dir":"Reference","previous_headings":"","what":"Aesthetics","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"aes() required. fact, aes() ignored.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"coords","dir":"Reference","previous_headings":"","what":"Coords","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"SpatRaster present crs (.e., terra::crs(rast) == \"\") geom make assumption scales. SpatRaster crs, geom uses ggplot2::coord_sf() adjust scales. means also SpatRaster may reprojected.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spatraster_rgb.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Visualise SpatRaster objects as images — geom_spatraster_rgb","text":"","code":"# \\donttest{ # Tile of Castille and Leon (Spain) from OpenStreetMap file_path <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") library(terra) tile <- rast(file_path) library(ggplot2) ggplot() + geom_spatraster_rgb(data = tile) + # You can use coord_sf coord_sf(crs = 3035) # Combine with sf objects vect_path <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") cyl_sf <- sf::st_read(vect_path) #> Reading layer `cyl' from data source #> `D:\\a\\_temp\\Library\\tidyterra\\extdata\\cyl.gpkg' using driver `GPKG' #> Simple feature collection with 9 features and 3 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: 2892687 ymin: 2017622 xmax: 3341372 ymax: 2361600 #> Projected CRS: ETRS89-extended / LAEA Europe ggplot(cyl_sf) + geom_spatraster_rgb(data = tile) + geom_sf(aes(fill = iso2)) + coord_sf(crs = 3857) + scale_fill_viridis_d(alpha = 0.7) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":null,"dir":"Reference","previous_headings":"","what":"Plot SpatRaster contours — geom_spat_contour","title":"Plot SpatRaster contours — geom_spat_contour","text":"geoms create contours SpatRaster objects. specify valid surface, specify layer aes(z = layer_name), otherwise layers consider creating contours. See also Facets section. underlying implementation based ggplot2::geom_contour(). geom_spatraster_contour_text() creates labeled contours implemented top isoband::isolines_grob().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Plot SpatRaster contours — geom_spat_contour","text":"","code":"geom_spatraster_contour( mapping = NULL, data, ..., maxcell = 5e+05, bins = NULL, binwidth = NULL, breaks = NULL, na.rm = TRUE, show.legend = NA, inherit.aes = TRUE ) geom_spatraster_contour_text( mapping = NULL, data, ..., maxcell = 5e+05, bins = NULL, binwidth = NULL, breaks = NULL, size.unit = \"mm\", label_format = scales::label_number(), label_placer = isoband::label_placer_minmax(), na.rm = TRUE, show.legend = NA, inherit.aes = TRUE ) geom_spatraster_contour_filled( mapping = NULL, data, ..., maxcell = 5e+05, bins = NULL, binwidth = NULL, breaks = NULL, na.rm = TRUE, show.legend = NA, inherit.aes = TRUE )"},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Plot SpatRaster contours — geom_spat_contour","text":"mapping Set aesthetic mappings created ggplot2::aes(). See Aesthetics specially use fill aesthetic. data SpatRaster object. ... arguments passed layer()'s params argument. arguments broadly fall one 4 categories . Notably, arguments position argument, aesthetics required can passed .... Unknown arguments part 4 categories ignored. Static aesthetics mapped scale, fixed value apply layer whole. example, colour = \"red\" linewidth = 3. geom's documentation Aesthetics section lists available options. 'required' aesthetics passed params. Please note passing unmapped aesthetics vectors technically possible, order required length guaranteed parallel input data. constructing layer using stat_*() function, ... argument can used pass parameters geom part layer. example stat_density(geom = \"area\", outline.type = \"\"). geom's documentation lists parameters can accept. Inversely, constructing layer using geom_*() function, ... argument can used pass parameters stat part layer. example geom_area(stat = \"density\", adjust = 0.5). stat's documentation lists parameters can accept. key_glyph argument layer() may also passed .... can one functions described key glyphs, change display layer legend. maxcell positive integer. Maximum number cells use plot. bins Number contour bins. Overridden breaks. binwidth width contour bins. Overridden bins. breaks One : Numeric vector set contour breaks function takes range data binwidth input returns breaks output. function can created formula (e.g. ~ fullseq(.x, .y)). Overrides binwidth bins. default, vector length ten pretty() breaks. na.rm TRUE, default, missing values silently removed. FALSE, missing values removed warning. show.legend logical. layer included legends? NA, default, includes aesthetics mapped. FALSE never includes, TRUE always includes. can also named logical vector finely select aesthetics display. inherit.aes FALSE, overrides default aesthetics, rather combining . size.unit size aesthetic interpreted: millimetres (\"mm\", default), points (\"pt\"), centimetres (\"cm\"), inches (\"\"), picas (\"pc\"). label_format One : NULL labels. produced result geom_spatraster_contour(). character vector giving labels (must length breaks produced bins, binwidth, breaks). function takes breaks input returns labels output, default setup (scales::label_number()). label_placer Function controls labels placed along isolines. Uses label_placer_minmax() default.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Plot SpatRaster contours — geom_spat_contour","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Plot SpatRaster contours — geom_spat_contour","text":"terra::contour()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"aesthetics","dir":"Reference","previous_headings":"","what":"Aesthetics","title":"Plot SpatRaster contours — geom_spat_contour","text":"geom_spatraster_contour() / geom_spatraster_contour_text() understands following aesthetics: alpha colour group linetype linewidth geom_spatraster_contour_text() understands also: size label family fontface Additionally, geom_spatraster_contour_filled() understands also following aesthetics, well ones listed : fill subgroup Check ggplot2::geom_contour() info contours vignette(\"ggplot2-specs\", package = \"ggplot2\") overview aesthetics.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"computed-variables","dir":"Reference","previous_headings":"","what":"Computed variables","title":"Plot SpatRaster contours — geom_spat_contour","text":"geom computes internally variables available use aesthetics, using (example) aes(color = after_stat()) (see ggplot2::after_stat()). after_stat(lyr): Name layer. after_stat(level): Height contour. contour lines, numeric vector represents bin boundaries. contour bands, ordered factor represents bin ranges. after_stat(nlevel): Height contour, scaled maximum 1. after_stat(level_low), after_stat(level_high), after_stat(level_mid): (contour bands ) Lower upper bin boundaries band, well mid point boundaries.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"dropped-variables","dir":"Reference","previous_headings":"","what":"Dropped variables","title":"Plot SpatRaster contours — geom_spat_contour","text":"z: contouring, z values individual data points longer available.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"coords","dir":"Reference","previous_headings":"","what":"Coords","title":"Plot SpatRaster contours — geom_spat_contour","text":"SpatRaster present crs (.e., terra::crs(rast) == \"\") geom make assumption scales. SpatRaster crs, geom uses ggplot2::coord_sf() adjust scales. means also SpatRaster may reprojected.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"facets","dir":"Reference","previous_headings":"","what":"Facets","title":"Plot SpatRaster contours — geom_spat_contour","text":"can use facet_wrap(~lyr) creating faceted plot layer SpatRaster object. See ggplot2::facet_wrap() details.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/geom_spat_contour.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Plot SpatRaster contours — geom_spat_contour","text":"","code":"# \\donttest{ library(terra) # Raster f <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") r <- rast(f) library(ggplot2) ggplot() + geom_spatraster_contour(data = r) # Labelled ggplot() + geom_spatraster_contour_text( data = r, breaks = c(110, 130, 160, 190), color = \"grey10\", family = \"serif\" ) ggplot() + geom_spatraster_contour( data = r, aes(color = after_stat(level)), binwidth = 1, linewidth = 0.4 ) + scale_color_gradientn( colours = hcl.colors(20, \"Inferno\"), guide = guide_coloursteps() ) + theme_minimal() # Filled with breaks ggplot() + geom_spatraster_contour_filled(data = r, breaks = seq(80, 200, 10)) + scale_fill_hypso_d() # Both lines and contours ggplot() + geom_spatraster_contour_filled( data = r, breaks = seq(80, 200, 10), alpha = .7 ) + geom_spatraster_contour( data = r, breaks = seq(80, 200, 2.5), color = \"grey30\", linewidth = 0.1 ) + scale_fill_hypso_d() # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":null,"dir":"Reference","previous_headings":"","what":"Visualise SpatVector objects — ggspatvector","title":"Visualise SpatVector objects — ggspatvector","text":"Wrappers ggplot2::geom_sf() family used visualise SpatVector objects (see terra::vect()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Visualise SpatVector objects — ggspatvector","text":"","code":"geom_spatvector( mapping = aes(), data = NULL, na.rm = FALSE, show.legend = NA, ... ) geom_spatvector_label( mapping = aes(), data = NULL, na.rm = FALSE, show.legend = NA, ..., nudge_x = 0, nudge_y = 0, label.size = 0.25, inherit.aes = TRUE ) geom_spatvector_text( mapping = aes(), data = NULL, na.rm = FALSE, show.legend = NA, ..., nudge_x = 0, nudge_y = 0, check_overlap = FALSE, inherit.aes = TRUE ) stat_spatvector( mapping = NULL, data = NULL, geom = \"rect\", position = \"identity\", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )"},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Visualise SpatVector objects — ggspatvector","text":"mapping Set aesthetic mappings created aes(). specified inherit.aes = TRUE (default), combined default mapping top level plot. must supply mapping plot mapping. data SpatVector object, see terra::vect(). na.rm FALSE, default, missing values removed warning. TRUE, missing values silently removed. show.legend logical. layer included legends? NA, default, includes aesthetics mapped. FALSE never includes, TRUE always includes. can also set one \"polygon\", \"line\", \"point\" override default legend. ... arguments passed ggplot2::geom_sf() functions. often aesthetics, used set aesthetic fixed value, like colour = \"red\" linewidth = 3. nudge_x, nudge_y Horizontal vertical adjustment nudge labels . Useful offsetting text points, particularly discrete scales. jointly specified position. label.size Size label border, mm. inherit.aes FALSE, overrides default aesthetics, rather combining . useful helper functions define data aesthetics inherit behaviour default plot specification, e.g. borders(). check_overlap TRUE, text overlaps previous text layer plotted. check_overlap happens draw time order data. Therefore data arranged label column calling geom_text(). Note argument supported geom_label(). geom geometric object use display data layer. using stat_*() function construct layer, geom argument can used override default coupling stats geoms. geom argument accepts following: Geom ggproto subclass, example GeomPoint. string naming geom. give geom string, strip function name geom_ prefix. example, use geom_point(), give geom \"point\". information ways specify geom, see layer geom documentation. position position adjustment use data layer. can used various ways, including prevent overplotting improving display. position argument accepts following: result calling position function, position_jitter(). method allows passing extra arguments position. string naming position adjustment. give position string, strip function name position_ prefix. example, use position_jitter(), give position \"jitter\". information ways specify position, see layer position documentation.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Visualise SpatVector objects — ggspatvector","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Visualise SpatVector objects — ggspatvector","text":"functions wrappers ggplot2::geom_sf() functions. Since fortify.SpatVector() method provided, ggplot2 treat SpatVector way sf object. side effect can use ggplot2::geom_sf() directly SpatVector objects. See ggplot2::geom_sf() details aesthetics, etc.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Visualise SpatVector objects — ggspatvector","text":"terra::plot()","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/ggspatvector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Visualise SpatVector objects — ggspatvector","text":"","code":"# \\donttest{ # Create a SpatVector extfile <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") cyl <- terra::vect(extfile) class(cyl) #> [1] \"SpatVector\" #> attr(,\"package\") #> [1] \"terra\" library(ggplot2) ggplot(cyl) + geom_spatvector() # With params ggplot(cyl) + geom_spatvector(aes(fill = name), color = NA) + scale_fill_viridis_d() + coord_sf(crs = 3857) # Add labels ggplot(cyl) + geom_spatvector(aes(fill = name), color = NA) + geom_spatvector_text(aes(label = iso2), fontface = \"bold\", color = \"red\" ) + scale_fill_viridis_d(alpha = 0.4) + coord_sf(crs = 3857) # You can use now geom_sf with SpatVectors! ggplot(cyl) + geom_sf() + labs( title = paste(\"cyl is\", as.character(class(cyl))), subtitle = \"With geom_sf()\" ) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Get a nice glimpse of your Spat* objects — glimpse.Spat","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"glimpse() like transposed version print(): layers/columns run page, data runs across. makes possible see every layer/column Spat* object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"","code":"# S3 method for class 'SpatRaster' glimpse(x, width = NULL, ..., n = 10, max_extra_cols = 20) # S3 method for class 'SpatVector' glimpse(x, width = NULL, ..., n = 10, max_extra_cols = 20)"},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"x SpatRaster created terra::rast() SpatVector created terra::vect(). width Width output: defaults setting width option (finite) width console. See dplyr::glimpse(). ... Arguments passed as_tibble() methods SpatRaster SpatVector. See as_tibble.SpatRaster(). n Maximum number rows show. max_extra_cols Number extra columns layers print abbreviated information , n small Spat* object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"original x (invisibly) returned, allowing glimpse() used within data pipeline.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"print()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"Implementation generic dplyr::glimpse() function Spat*. objects.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/glimpse.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get a nice glimpse of your Spat* objects — glimpse.Spat","text":"","code":"library(terra) # SpatVector v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) v %>% glimpse(n = 2) #> # A SpatVector 9 x 3 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\", \"ES… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> # ℹ 1 more variable : name #> # ℹ Use `tidyterra::glimpse(n = ...)` to see more columns # Use on a pipeline v %>% glimpse() %>% mutate(a = 30) %>% # with options glimpse(geom = \"WKT\") #> # A SpatVector 9 x 3 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\", \"ES… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia\", \"S… #> # A SpatVector 9 x 4 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\",… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia\"… #> $ a 30, 30, 30, 30, 30, 30, 30, 30, 30 #> $ geometry \"POLYGON ((3126360.2417 2066777.7545, 3125073.9752 2065007.29… # SpatRaster r <- rast(system.file(\"extdata/cyl_elev.tif\", package = \"tidyterra\")) r %>% glimpse() #> # A SpatRaster 126 x 212 x 1 layer (26,712 cells) #> # Resolution (x / y): (1' 30\" , 1' 30\") #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([7° 4' 30\" W / 1° 46' 30\" W] , [40° 4' 60\" N / 43° 13' 60\" N]) #> #> $ elevation_m 700.2969, 780.3889, 706.1250, 568.9722, 584.9028, 506.7361… # Use on a pipeline r %>% glimpse() %>% mutate(b = elevation_m / 100) %>% # With options glimpse(xy = TRUE) #> # A SpatRaster 126 x 212 x 1 layer (26,712 cells) #> # Resolution (x / y): (1' 30\" , 1' 30\") #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([7° 4' 30\" W / 1° 46' 30\" W] , [40° 4' 60\" N / 43° 13' 60\" N]) #> #> $ elevation_m 700.2969, 780.3889, 706.1250, 568.9722, 584.9028, 506.7361… #> # A SpatRaster 126 x 212 x 2 layers (26,712 cells) #> # Resolution (x / y): (1' 30\" , 1' 30\") #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([7° 4' 30\" W / 1° 46' 30\" W] , [40° 4' 60\" N / 43° 13' 60\" N]) #> #> $ elevation_m 700.2969, 780.3889, 706.1250, 568.9722, 584.9028, 506.7361… #> $ b 7.002969, 7.803889, 7.061250, 5.689722, 5.849028, 5.067361…"},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":null,"dir":"Reference","previous_headings":"","what":"GRASS color tables — grass_db","title":"GRASS color tables — grass_db","text":"tibble including color map 51 gradient palettes. palettes includes also definition colors limits can used ggplot2::scale_fill_gradientn().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"GRASS color tables — grass_db","text":"tibble 2920 rows 6 columns. following fields: pal Name palette. limit (Optional) limit color. r Value red channel (RGB color mode). g Value green channel (RGB color mode). b Value blue channel (RGB color mode). hex Hex code color.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"GRASS color tables — grass_db","text":"Derived https://github.com/OSGeo/grass/tree/main/lib/gis/colors. See also r.color - GRASS GIS Manual.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"GRASS color tables — grass_db","text":"Summary palettes provided, description recommended use:","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"GRASS color tables — grass_db","text":"terra::map.pal()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"GRASS color tables — grass_db","text":"GRASS Development Team (2024). Geographic Resources Analysis Support System (GRASS) Software, Version 8.3.2. Open Source Geospatial Foundation, USA. https://grass.osgeo.org.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/grass_db.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"GRASS color tables — grass_db","text":"","code":"# \\donttest{ data(\"grass_db\") grass_db #> # A tibble: 2,920 × 6 #> pal limit r g b hex #> #> 1 aspect NA 0 0 0 #000000 #> 2 aspect NA 255 255 255 #FFFFFF #> 3 aspect NA 0 0 0 #000000 #> 4 aspectcolr 0 255 255 255 #FFFFFF #> 5 aspectcolr 1 255 255 0 #FFFF00 #> 6 aspectcolr 90 0 255 0 #00FF00 #> 7 aspectcolr 180 0 255 255 #00FFFF #> 8 aspectcolr 270 255 0 0 #FF0000 #> 9 aspectcolr 360 255 255 0 #FFFF00 #> 10 bcyr NA 0 0 255 #0000FF #> # ℹ 2,910 more rows # Select a palette srtm_plus <- grass_db %>% filter(pal == \"srtm_plus\") f <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") r <- terra::rast(f) library(ggplot2) p <- ggplot() + geom_spatraster(data = r) + labs(fill = \"elevation\") p + scale_fill_gradientn(colors = srtm_plus$hex) # Use with limits p + scale_fill_gradientn( colors = srtm_plus$hex, values = scales::rescale(srtm_plus$limit), limit = range(srtm_plus$limit), na.value = \"lightblue\" ) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Group a SpatVector by one or more variables — group-by.SpatVector","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"data operations done groups defined variables. group_by.SpatVector() adds new attributes existing SpatVector indicating corresponding groups. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"","code":"# S3 method for class 'SpatVector' group_by(.data, ..., .add = FALSE, .drop = group_by_drop_default(.data)) # S3 method for class 'SpatVector' ungroup(x, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":".data, x SpatVector object. See Methods. ... group_by(), variables computations group . Computations always done ungrouped data frame. perform computations grouped data, need use separate mutate() step group_by(). Computations allowed nest_by(). ungroup(), variables remove grouping. .add FALSE, default, group_by() override existing groups. add existing groups, use .add = TRUE. argument previously called add, prevented creating new grouping variable called add, conflicts naming conventions. .drop Drop groups formed factor levels appear data? default TRUE except .data previously grouped .drop = FALSE. See group_by_drop_default() details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"SpatVector object additional attribute.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"See Details dplyr::group_by().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"Implementation generic dplyr::group_by() family functions SpatVector objects. mixing terra dplyr syntax grouped SpatVector (.e, subsetting SpatVector like v[1:3,1:2]) groups attribute can corrupted. tidyterra try re-group SpatVector. triggered next time use dplyr verb SpatVector. Note also operations (terra::spatSample()) create new SpatVector. cases, result preserve groups attribute. Use group_by() re-group.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/group-by.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Group a SpatVector by one or more variables — group-by.SpatVector","text":"","code":"# \\donttest{ library(terra) f <- system.file(\"ex/lux.shp\", package = \"terra\") p <- vect(f) by_name1 <- p %>% group_by(NAME_1) # grouping doesn't change how the SpatVector looks by_name1 #> class : SpatVector #> geometry : polygons #> dimensions : 12, 6 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> source : lux.shp #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : ID_1 NAME_1 ID_2 NAME_2 AREA POP #> type : #> values : 1 Diekirch 1 Clervaux 312 1.808e+04 #> 1 Diekirch 2 Diekirch 218 3.254e+04 #> 1 Diekirch 3 Redange 259 1.866e+04 # But add metadata for grouping: See the coercion to tibble # Not grouped p_tbl <- as_tibble(p) class(p_tbl) #> [1] \"tbl_df\" \"tbl\" \"data.frame\" head(p_tbl, 3) #> # A tibble: 3 × 6 #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 Diekirch 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 Diekirch 3 Redange 259 18664 # Grouped by_name1_tbl <- as_tibble(by_name1) class(by_name1_tbl) #> [1] \"grouped_df\" \"tbl_df\" \"tbl\" \"data.frame\" head(by_name1_tbl, 3) #> # A tibble: 3 × 6 #> # Groups: NAME_1 [1] #> ID_1 NAME_1 ID_2 NAME_2 AREA POP #> #> 1 1 Diekirch 1 Clervaux 312 18081 #> 2 1 Diekirch 2 Diekirch 218 32543 #> 3 1 Diekirch 3 Redange 259 18664 # It changes how it acts with the other dplyr verbs: by_name1 %>% summarise( pop = mean(POP), area = sum(AREA) ) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 3 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_1 pop area #> type : #> values : Diekirch 1.824e+04 1128 #> Grevenmacher 2.37e+04 527 #> Luxembourg 1.099e+05 906 # Each call to summarise() removes a layer of grouping by_name2_name1 <- p %>% group_by(NAME_2, NAME_1) by_name2_name1 #> class : SpatVector #> geometry : polygons #> dimensions : 12, 6 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> source : lux.shp #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : ID_1 NAME_1 ID_2 NAME_2 AREA POP #> type : #> values : 1 Diekirch 1 Clervaux 312 1.808e+04 #> 1 Diekirch 2 Diekirch 218 3.254e+04 #> 1 Diekirch 3 Redange 259 1.866e+04 group_data(by_name2_name1) #> # A tibble: 12 × 3 #> NAME_2 NAME_1 .rows #> > #> 1 Capellen Luxembourg [1] #> 2 Clervaux Diekirch [1] #> 3 Diekirch Diekirch [1] #> 4 Echternach Grevenmacher [1] #> 5 Esch-sur-Alzette Luxembourg [1] #> 6 Grevenmacher Grevenmacher [1] #> 7 Luxembourg Luxembourg [1] #> 8 Mersch Luxembourg [1] #> 9 Redange Diekirch [1] #> 10 Remich Grevenmacher [1] #> 11 Vianden Diekirch [1] #> 12 Wiltz Diekirch [1] by_name2 <- by_name2_name1 %>% summarise(n = dplyr::n()) by_name2 #> class : SpatVector #> geometry : polygons #> dimensions : 12, 3 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_2 NAME_1 n #> type : #> values : Capellen Luxembourg 1 #> Clervaux Diekirch 1 #> Diekirch Diekirch 1 group_data(by_name2) #> # A tibble: 12 × 2 #> NAME_2 .rows #> > #> 1 Capellen [1] #> 2 Clervaux [1] #> 3 Diekirch [1] #> 4 Echternach [1] #> 5 Esch-sur-Alzette [1] #> 6 Grevenmacher [1] #> 7 Luxembourg [1] #> 8 Mersch [1] #> 9 Redange [1] #> 10 Remich [1] #> 11 Vianden [1] #> 12 Wiltz [1] # To removing grouping, use ungroup by_name2 %>% ungroup() %>% summarise(n = sum(n)) #> class : SpatVector #> geometry : polygons #> dimensions : 1, 1 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : n #> type : #> values : 12 # By default, group_by() overrides existing grouping by_name2_name1 %>% group_by(ID_1, ID_2) %>% group_vars() #> [1] \"ID_1\" \"ID_2\" # Use add = TRUE to instead append by_name2_name1 %>% group_by(ID_1, ID_2, .add = TRUE) %>% group_vars() #> [1] \"NAME_2\" \"NAME_1\" \"ID_1\" \"ID_2\" # You can group by expressions: this is a short-hand # for a mutate() followed by a group_by() p %>% group_by(ID_COMB = ID_1 * 100 / ID_2) %>% relocate(ID_COMB, .before = 1) #> class : SpatVector #> geometry : polygons #> dimensions : 12, 7 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> source : lux.shp #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : ID_COMB ID_1 NAME_1 ID_2 NAME_2 AREA POP #> type : #> values : 100 1 Diekirch 1 Clervaux 312 1.808e+04 #> 50 1 Diekirch 2 Diekirch 218 3.254e+04 #> 33.33 1 Diekirch 3 Redange 259 1.866e+04 # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/group_data.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Grouping metadata for SpatVector objects — group_data.SpatVector","title":"Grouping metadata for SpatVector objects — group_data.SpatVector","text":"collection functions accesses data grouped SpatVector objects various ways: group_data() returns tibble defines grouping structure. columns give values grouping variables. last column, always called .rows, list integer vectors gives location rows group. group_keys() returns tibble describing groups. group_rows() returns list integer vectors giving rows group contains. group_indices() returns integer vector length .data gives group row belongs . group_vars() gives names grouping variables character vector. groups() gives names grouping variables list symbols. group_size() gives size group. n_groups() gives total number groups. See dplyr::group_data().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group_data.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Grouping metadata for SpatVector objects — group_data.SpatVector","text":"","code":"# S3 method for class 'SpatVector' group_data(.data) # S3 method for class 'SpatVector' group_keys(.tbl, ...) # S3 method for class 'SpatVector' group_indices(.data, ...) # S3 method for class 'SpatVector' group_vars(x) # S3 method for class 'SpatVector' groups(x) # S3 method for class 'SpatVector' group_size(x) # S3 method for class 'SpatVector' n_groups(x)"},{"path":"https://dieghernan.github.io/tidyterra/reference/group_data.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Grouping metadata for SpatVector objects — group_data.SpatVector","text":".data, .tbl, x SpatVector. ... Use ... now deprecated; please use group_by() first instead.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group_data.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Grouping metadata for SpatVector objects — group_data.SpatVector","text":"See description function. results usually tibbles, lists vectors. functions return SpatVector objects.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/group_data.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Grouping metadata for SpatVector objects — group_data.SpatVector","text":"","code":"library(terra) v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) v$gr_1 <- rep_len(c(\"A\", \"A\", \"B\"), length.out = nrow(v)) v$gr_2 <- rep_len(c(\"C\", \"D\"), length.out = nrow(v)) # Ungrouped n_groups(v) #> [1] 1 group_vars(v) #> character(0) group_keys(v) #> # A tibble: 1 × 0 group_size(v) #> [1] 9 groups(v) #> list() group_rows(v) #> [1]> #> [[1]] #> [1] 1 2 3 4 5 6 7 8 9 #> group_data(v) #> # A tibble: 1 × 1 #> .rows #> > #> 1 [9] group_indices(v) #> [1] 1 1 1 1 1 1 1 1 1 # Grouped by one var gv <- group_by(v, gr_1) n_groups(gv) #> [1] 2 group_vars(gv) #> [1] \"gr_1\" group_keys(gv) #> # A tibble: 2 × 1 #> gr_1 #> #> 1 A #> 2 B group_size(gv) #> [1] 6 3 groups(gv) #> [[1]] #> gr_1 #> group_rows(gv) #> [2]> #> [[1]] #> [1] 1 2 4 5 7 8 #> #> [[2]] #> [1] 3 6 9 #> group_data(gv) #> # A tibble: 2 × 2 #> gr_1 .rows #> > #> 1 A [6] #> 2 B [3] group_indices(gv) #> [1] 1 1 2 1 1 2 1 1 2 # Grouped by several vars gv2 <- group_by(v, gr_1, gr_2) n_groups(gv2) #> [1] 4 group_vars(gv2) #> [1] \"gr_1\" \"gr_2\" group_keys(gv2) #> # A tibble: 4 × 2 #> gr_1 gr_2 #> #> 1 A C #> 2 A D #> 3 B C #> 4 B D group_size(gv2) #> [1] 3 3 2 1 groups(gv2) #> [[1]] #> gr_1 #> #> [[2]] #> gr_2 #> group_rows(gv2) #> [4]> #> [[1]] #> [1] 1 5 7 #> #> [[2]] #> [1] 2 4 8 #> #> [[3]] #> [1] 3 9 #> #> [[4]] #> [1] 6 #> group_data(gv2) #> # A tibble: 4 × 3 #> gr_1 gr_2 .rows #> > #> 1 A C [3] #> 2 A D [3] #> 3 B C [2] #> 4 B D [1] group_indices(gv2) #> [1] 1 2 3 2 1 4 1 2 3"},{"path":"https://dieghernan.github.io/tidyterra/reference/hypsometric_tints_db.html","id":null,"dir":"Reference","previous_headings":"","what":"Hypsometric palettes database — hypsometric_tints_db","title":"Hypsometric palettes database — hypsometric_tints_db","text":"tibble including color map 33 gradient palettes. palettes includes also definition colors limits terms elevation (meters), can used ggplot2::scale_fill_gradientn().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/hypsometric_tints_db.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Hypsometric palettes database — hypsometric_tints_db","text":"tibble 1102 rows 6 columns. following fields: pal Name palette. limit Recommended elevation limit (meters) color. r Value red channel (RGB color mode). g Value green channel (RGB color mode). b Value blue channel (RGB color mode). hex Hex code color.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/hypsometric_tints_db.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Hypsometric palettes database — hypsometric_tints_db","text":"cpt-city: http://seaviewsensing.com/pub/cpt-city/.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/hypsometric_tints_db.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Hypsometric palettes database — hypsometric_tints_db","text":"","code":"# \\donttest{ data(\"hypsometric_tints_db\") hypsometric_tints_db #> # A tibble: 1,102 × 6 #> pal limit r g b hex #> #> 1 arctic -5000 44 53 99 #2C3563 #> 2 arctic -4900 46 54 100 #2E3664 #> 3 arctic -4800 48 56 103 #303867 #> 4 arctic -4700 50 59 106 #323B6A #> 5 arctic -4600 52 60 107 #343C6B #> 6 arctic -4500 54 61 109 #363D6D #> 7 arctic -4400 56 63 111 #383F6F #> 8 arctic -4300 57 65 113 #394171 #> 9 arctic -4200 60 68 116 #3C4474 #> 10 arctic -4100 62 70 118 #3E4676 #> # ℹ 1,092 more rows # Select a palette wikicols <- hypsometric_tints_db %>% filter(pal == \"wiki-2.0\") f <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") r <- terra::rast(f) library(ggplot2) p <- ggplot() + geom_spatraster(data = r) + labs(fill = \"elevation\") p + scale_fill_gradientn(colors = wikicols$hex) # Use with limits p + scale_fill_gradientn( colors = wikicols$hex, values = scales::rescale(wikicols$limit), limit = range(wikicols$limit) ) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/is_grouped_spatvector.html","id":null,"dir":"Reference","previous_headings":"","what":"A grouped SpatVector — is_grouped_spatvector","title":"A grouped SpatVector — is_grouped_spatvector","text":"easiest way create grouped SpatVector call group_by() method SpatVector: take care capturing unevaluated expressions . See group_by.SpatVector() details. function adapted version dplyr::is_grouped_df(). See also group_data.SpatVector() accessory functions retrieve various metadata grouped SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/is_grouped_spatvector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"A grouped SpatVector — is_grouped_spatvector","text":"","code":"is_grouped_spatvector(x)"},{"path":"https://dieghernan.github.io/tidyterra/reference/is_grouped_spatvector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"A grouped SpatVector — is_grouped_spatvector","text":"x SpatVector.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/is_regular_grid.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if x and y positions conforms a regular grid — is_regular_grid","title":"Check if x and y positions conforms a regular grid — is_regular_grid","text":"Assess coordinates x,y object conforms regular grid. function called side effects. function internally called as_spatraster().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/is_regular_grid.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if x and y positions conforms a regular grid — is_regular_grid","text":"","code":"is_regular_grid(xy, digits = 6)"},{"path":"https://dieghernan.github.io/tidyterra/reference/is_regular_grid.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if x and y positions conforms a regular grid — is_regular_grid","text":"xy matrix, data frame tibble least two columns representing x y coordinates. digits integer set precision detecting whether points regular grid (low number digits low precision).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/is_regular_grid.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check if x and y positions conforms a regular grid — is_regular_grid","text":"invisible() regular error message otherwise","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/is_regular_grid.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check if x and y positions conforms a regular grid — is_regular_grid","text":"","code":"p <- matrix(1:90, nrow = 45, ncol = 2) is_regular_grid(p) # Jitter location set.seed(1234) jitter <- runif(length(p)) / 10e4 p_jitter <- p + jitter # Need to adjust digits is_regular_grid(p_jitter, digits = 4)"},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"Mutating joins add columns y x, matching observations based keys. four mutating joins: inner join, three outer joins. See dplyr::inner_join() details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"","code":"# S3 method for class 'SpatVector' inner_join( x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = NULL ) # S3 method for class 'SpatVector' left_join( x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = NULL ) # S3 method for class 'SpatVector' right_join( x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = NULL ) # S3 method for class 'SpatVector' full_join( x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = NULL )"},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"x SpatVector created terra::vect(). y data frame object coercible data frame. SpatVector sf object provided return error (see terra::intersect() performing spatial joins). join specification created join_by(), character vector variables join . NULL, default, *_join() perform natural join, using variables common across x y. message lists variables can check correct; suppress message supplying explicitly. join different variables x y, use join_by() specification. example, join_by(== b) match x$y$b. join multiple variables, use join_by() specification multiple expressions. example, join_by(== b, c == d) match x$y$b x$c y$d. column names x y, can shorten listing variable names, like join_by(, c). join_by() can also used perform inequality, rolling, overlap joins. See documentation ?join_by details types joins. simple equality joins, can alternatively specify character vector variable names join . example, = c(\"\", \"b\") joins x$y$x$b y$b. variable names differ x y, use named character vector like = c(\"x_a\" = \"y_a\", \"x_b\" = \"y_b\"). perform cross-join, generating combinations x y, see cross_join(). copy x y data source, copy TRUE, y copied src x. allows join tables across srcs, potentially expensive operation must opt . suffix non-joined duplicate variables x y, suffixes added output disambiguate . character vector length 2. ... parameters passed onto methods. keep join keys x y preserved output? NULL, default, joins equality retain keys x, joins inequality retain keys inputs. TRUE, keys inputs retained. FALSE, keys x retained. right full joins, data key columns corresponding rows exist y merged key columns x. used joining inequality conditions.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"terra::merge()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"Implementation generic dplyr::inner_join() family","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"geometry column sticky behavior. means result always geometry x records matches join conditions. Note right_join() full_join() possible return empty geometries (since y expected data frame geometries). Although kind joining operations may common spatial manipulation, possible function crashes, since handling EMPTY geometries differs terra sf.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate-joins.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Mutating joins for SpatVector objects — mutate-joins.SpatVector","text":"","code":"library(terra) library(ggplot2) # Vector v <- terra::vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) # A data frame df <- data.frame( cpro = sprintf(\"%02d\", 1:10), x = runif(10), y = runif(10), letter = rep_len(LETTERS[1:3], length.out = 10) ) # Inner join inner <- v %>% inner_join(df) #> Joining with `by = join_by(cpro)` nrow(inner) #> [1] 2 autoplot(inner, aes(fill = letter)) + ggtitle(\"Inner Join\") # Left join left <- v %>% left_join(df) #> Joining with `by = join_by(cpro)` nrow(left) #> [1] 9 autoplot(left, aes(fill = letter)) + ggtitle(\"Left Join\") # \\donttest{ # Right join right <- v %>% right_join(df) #> Joining with `by = join_by(cpro)` nrow(right) #> [1] 10 autoplot(right, aes(fill = letter)) + ggtitle(\"Right Join\") # There are empty geometries, check with data from df ggplot(right, aes(x, y)) + geom_point(aes(color = letter)) # Full join full <- v %>% full_join(df) #> Joining with `by = join_by(cpro)` nrow(full) #> [1] 17 autoplot(full, aes(fill = letter)) + ggtitle(\"Full Join\") # Check with data from df ggplot(full, aes(x, y)) + geom_point(aes(color = letter)) #> Warning: Removed 7 rows containing missing values or values outside the scale range #> (`geom_point()`). # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"mutate() adds new layers/attributes preserves existing ones Spat* object. transmute() adds new layers/attributes drops existing ones. New variables overwrite existing variables name. Variables can removed setting value NULL.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"","code":"# S3 method for class 'SpatRaster' mutate(.data, ...) # S3 method for class 'SpatVector' mutate(.data, ...) # S3 method for class 'SpatRaster' transmute(.data, ...) # S3 method for class 'SpatVector' transmute(.data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... Name-value pairs. name gives name layer/attribute output.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"terra methods modifying cell values: terra::ifel(), terra::classify(), terra::clamp(), terra::app(), terra::lapp(), terra::tapp()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"Implementation generic dplyr::mutate(), dplyr::transmute() functions.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"Add new layers preserves existing ones. result SpatRaster extent, resolution crs .data. values (possibly number) layers modified. transmute() keep layers created ....","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"result SpatVector modified (possibly renamed) attributes function call. transmute() keep attributes created ....","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/mutate.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create, modify, and delete cell values/layers/attributes of Spat* objects — mutate.Spat","text":"","code":"library(terra) # SpatRaster method f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") spatrast <- rast(f) mod <- spatrast %>% mutate(exp_lyr1 = exp(tavg_04 / 10)) %>% select(tavg_04, exp_lyr1) mod #> class : SpatRaster #> dimensions : 87, 118, 2 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source(s) : memory #> names : tavg_04, exp_lyr1 #> min values : 1.885463, 1.207493 #> max values : 13.283829, 3.774934 plot(mod) # SpatVector method f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- vect(f) v %>% mutate(cpro2 = paste0(cpro, \"-CyL\")) %>% select(cpro, cpro2) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 2 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro cpro2 #> type : #> values : 05 05-CyL #> 09 09-CyL #> 24 24-CyL"},{"path":"https://dieghernan.github.io/tidyterra/reference/pipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Pipe operator — %>%","title":"Pipe operator — %>%","text":"See magrittr::%>% details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pipe operator — %>%","text":"","code":"lhs %>% rhs"},{"path":"https://dieghernan.github.io/tidyterra/reference/pipe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pipe operator — %>%","text":"lhs value magrittr placeholder. rhs function call using magrittr semantics.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pipe operator — %>%","text":"result calling rhs(lhs).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"pivot_longer() \"lengthens\" data, increasing number rows decreasing number columns. inverse transformation pivot_wider.SpatVector() Learn tidyr::pivot_wider().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"","code":"# S3 method for class 'SpatVector' pivot_longer( data, cols, ..., cols_vary = \"fastest\", names_to = \"name\", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = NULL, names_transform = NULL, names_repair = \"check_unique\", values_to = \"value\", values_drop_na = FALSE, values_ptypes = NULL, values_transform = NULL )"},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"data SpatVector pivot. cols Columns pivot longer format. ... Additional arguments passed methods. cols_vary pivoting cols longer format, output rows arranged relative original row number? \"fastest\", default, keeps individual rows cols close together output. often produces intuitively ordered output least one key column data involved pivoting process. \"slowest\" keeps individual columns cols close together output. often produces intuitively ordered output utilize columns data pivoting process. names_to character vector specifying new column columns create information stored column names data specified cols. length 0, NULL supplied, columns created. length 1, single column created contain column names specified cols. length >1, multiple columns created. case, one names_sep names_pattern must supplied specify column names split. also two additional character values can take advantage : NA discard corresponding component column name. \".value\" indicates corresponding component column name defines name output column containing cell values, overriding values_to entirely. names_prefix regular expression used remove matching text start variable name. names_sep, names_pattern names_to contains multiple values, arguments control column name broken . names_sep takes specification separate(), can either numeric vector (specifying positions break ), single string (specifying regular expression split ). names_pattern takes specification extract(), regular expression containing matching groups (()). arguments give enough control, use pivot_longer_spec() create spec object process manually needed. names_ptypes, values_ptypes Optionally, list column name-prototype pairs. Alternatively, single empty prototype can supplied, applied columns. prototype (ptype short) zero-length vector (like integer() numeric()) defines type, class, attributes vector. Use arguments want confirm created columns types expect. Note want change (instead confirm) types specific columns, use names_transform values_transform instead. names_transform, values_transform Optionally, list column name-function pairs. Alternatively, single function can supplied, applied columns. Use arguments need change types specific columns. example, names_transform = list(week = .integer) convert character variable called week integer. specified, type columns generated names_to character, type variables generated values_to common type input columns used generate . names_repair happens output invalid column names? default, \"check_unique\" error columns duplicated. Use \"minimal\" allow duplicates output, \"unique\" de-duplicated adding numeric suffixes. See vctrs::vec_as_names() options. values_to string specifying name column create data stored cell values. names_to character containing special .value sentinel, value ignored, name value column derived part existing column names. values_drop_na TRUE, drop rows contain NAs value_to column. effectively converts explicit missing values implicit missing values, generally used missing values data created structure.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"Implementation generic tidyr::pivot_longer() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"geometry column sticky behavior. means result always geometry data.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_longer.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Pivot SpatVector from wide to long — pivot_longer.SpatVector","text":"","code":"# \\donttest{ library(dplyr) library(tidyr) #> #> Attaching package: 'tidyr' #> The following object is masked from 'package:terra': #> #> extract library(ggplot2) library(terra) temp <- rast((system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\"))) cyl <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) %>% project(temp) # Add average temp temps <- terra::extract(temp, cyl, fun = \"mean\", na.rm = TRUE, xy = TRUE) cyl_temp <- cbind(cyl, temps) %>% glimpse() #> # A SpatVector 9 x 7 #> # Geometry type: Polygons #> # Projected CRS: World_Robinson #> # CRS projection units: meter #> # Extent (x / y) : ([ -607,946.2 / -153,819.7] , [4,285,436.1 / 4,619,242.7]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\", … #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia\",… #> $ ID 1, 2, 3, 4, 5, 6, 7, 8, 9 #> $ tavg_04 8.098067, 8.405818, 7.566549, 8.558559, 9.593332, 8.727293, 7.… #> $ tavg_05 11.84584, 12.07354, 11.09056, 12.11431, 13.00844, 12.35747, 11… #> $ tavg_06 16.64684, 16.14488, 15.51468, 16.45461, 17.55421, 17.05671, 16… # And pivot long for plot cyl_temp %>% pivot_longer( cols = tavg_04:tavg_06, names_to = \"label\", values_to = \"temp\" ) %>% ggplot() + geom_spatvector(aes(fill = temp)) + facet_wrap(~label, ncol = 1) + scale_fill_whitebox_c(palette = \"muted\") # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"pivot_wider() \"widens\" SpatVector, increasing number columns decreasing number rows. inverse transformation pivot_longer.SpatVector().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"","code":"# S3 method for class 'SpatVector' pivot_wider( data, ..., id_cols = NULL, id_expand = FALSE, names_from = \"name\", names_prefix = \"\", names_sep = \"_\", names_glue = NULL, names_sort = FALSE, names_vary = \"fastest\", names_expand = FALSE, names_repair = \"check_unique\", values_from = \"value\", values_fill = NULL, values_fn = NULL, unused_fn = NULL )"},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"data SpatVector pivot. ... Additional arguments passed methods. id_cols set columns uniquely identify observation. Typically used redundant variables, .e. variables whose values perfectly correlated existing variables. Defaults columns data except columns specified names_from values_from. tidyselect expression supplied, evaluated data removing columns specified names_from values_from. Note \"geometry\" columns sticky, hence removed names_from values_from. id_expand values id_cols columns expanded expand() pivoting? results rows, output contain complete expansion possible values id_cols. Implicit factor levels represented data become explicit. Additionally, row values corresponding expanded id_cols sorted. names_from, values_from pair arguments describing column (columns) get name output column (names_from), column (columns) get cell values (values_from). values_from contains multiple values, value added front output column. names_prefix regular expression used remove matching text start variable name. names_sep names_from values_from contains multiple variables, used join values together single string use column name. names_glue Instead names_sep names_prefix, can supply glue specification uses names_from columns (special .value) create custom column names. names_sort column names sorted? FALSE, default, column names ordered first appearance. names_vary names_from identifies column (columns) multiple unique values, multiple values_from columns provided, order resulting column names combined? \"fastest\" varies names_from values fastest, resulting column naming scheme form: value1_name1, value1_name2, value2_name1, value2_name2. default. \"slowest\" varies names_from values slowest, resulting column naming scheme form: value1_name1, value2_name1, value1_name2, value2_name2. names_expand values names_from columns expanded expand() pivoting? results columns, output contain column names corresponding complete expansion possible values names_from. Implicit factor levels represented data become explicit. Additionally, column names sorted, identical names_sort produce. names_repair happens output invalid column names? default, \"check_unique\" error columns duplicated. Use \"minimal\" allow duplicates output, \"unique\" de-duplicated adding numeric suffixes. See vctrs::vec_as_names() options. values_fill Optionally, (scalar) value specifies value filled missing. can named list want apply different fill values different value columns. values_fn Optionally, function applied value cell output. typically use combination id_cols names_from columns uniquely identify observation. can named list want apply different aggregations different values_from columns. unused_fn Optionally, function applied summarize values unused columns (.e. columns identified id_cols, names_from, values_from). default drops unused columns result. can named list want apply different aggregations different unused columns. id_cols must supplied unused_fn useful, since otherwise unspecified columns considered id_cols. similar grouping id_cols summarizing unused columns using unused_fn.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"Implementation generic tidyr::pivot_wider() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"geometry column sticky behavior. means result always geometry data.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/pivot_wider.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Pivot SpatVector from long to wide — pivot_wider.SpatVector","text":"","code":"# \\donttest{ library(dplyr) library(tidyr) library(ggplot2) cyl <- terra::vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) # Add extra row with info xtra <- cyl %>% slice(c(2, 3)) %>% mutate( label = \"extra\", value = TRUE ) %>% rbind(cyl, .) %>% glimpse() #> # A SpatVector 11 x 5 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\", \"E… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\", \"09\", \"24\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia\", \"… #> $ label NA, NA, NA, NA, NA, NA, NA, NA, NA, \"extra\", \"extra\" #> $ value NA, NA, NA, NA, NA, NA, NA, NA, NA, TRUE, TRUE # Pivot by geom xtra %>% pivot_wider( id_cols = iso2:name, values_from = value, names_from = label ) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 5 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name NA extra #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos TRUE #> ES-LE 24 Leon TRUE # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/princess_db.html","id":null,"dir":"Reference","previous_headings":"","what":"Princess palettes database — princess_db","title":"Princess palettes database — princess_db","text":"tibble including color map 15 gradient palettes.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/princess_db.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Princess palettes database — princess_db","text":"tibble 75 rows 5 columns. following fields: pal Name palette. r Value red channel (RGB color mode). g Value green channel (RGB color mode). b Value blue channel (RGB color mode). hex Hex code color.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/princess_db.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Princess palettes database — princess_db","text":"https://leahsmyth.github.io/Princess-Colour-Schemes/index.html.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/princess_db.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Princess palettes database — princess_db","text":"","code":"# \\donttest{ data(\"princess_db\") princess_db #> # A tibble: 75 × 5 #> pal r g b hex #> #> 1 snow 227 75 98 #e34b62 #> 2 snow 138 192 229 #8ac0e5 #> 3 snow 10 100 165 #0a64a5 #> 4 snow 255 235 148 #ffeb94 #> 5 snow 255 202 53 #ffca35 #> 6 ella 215 234 246 #d7eaf6 #> 7 ella 177 222 245 #b1def5 #> 8 ella 140 197 232 #8cc5e8 #> 9 ella 59 139 189 #3b8bbd #> 10 ella 40 98 135 #286287 #> # ℹ 65 more rows # Select a palette maori <- princess_db %>% filter(pal == \"maori\") f <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") r <- terra::rast(f) library(ggplot2) p <- ggplot() + geom_spatraster(data = r) + labs(fill = \"elevation\") p + scale_fill_gradientn(colors = maori$hex) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract a single layer/attribute — pull.Spat","title":"Extract a single layer/attribute — pull.Spat","text":"pull() similar $ data frame. mostly useful looks little nicer pipes can optionally name output. possible extract geographic coordinates SpatRaster. need use pull(.data, x, xy = TRUE). x y reserved names terra, since refer geographic coordinates layer. See Examples section layer names as_tibble.Spat().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract a single layer/attribute — pull.Spat","text":"","code":"# S3 method for class 'SpatRaster' pull(.data, var = -1, name = NULL, ...) # S3 method for class 'SpatVector' pull(.data, var = -1, name = NULL, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract a single layer/attribute — pull.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). var variable specified : literal layer/attribute name. positive integer, giving position counting left. negative integer, giving position counting right. default returns last layer/attribute (assumption column created recently). name optional parameter specifies column used names named vector. Specified similar manner var. ... Arguments passed as_tibble.Spat()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract a single layer/attribute — pull.Spat","text":"vector number cells/geometries .data. SpatRaster objects, note default (na.rm = FALSE) remove empty cells, may need pass (na.rm = FALSE) .... See terra::.data.frame().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Extract a single layer/attribute — pull.Spat","text":"terra::values()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Extract a single layer/attribute — pull.Spat","text":"Implementation generic dplyr::pull() function. done coercing Spat* object tibble first (see as_tibble.Spat) using dplyr::pull() method tibble.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Extract a single layer/attribute — pull.Spat","text":"passing option na.rm = TRUE ..., cells value distinct NA extracted. See terra::.data.frame(). xy = TRUE option passed ..., two columns names x y (corresponding geographic coordinates cell) available position 1 2. Hence, pull(.data, 1) pull(.data, 1, xy = TRUE) return different result.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Extract a single layer/attribute — pull.Spat","text":"passing geom = \"WKT\"/geom = \"HEX\" ..., geometry SpatVector can pulled passing var = geometry. Similarly SpatRaster method, using geom = \"XY\" x,y coordinates can pulled var = x/var = y. See terra::.data.frame() options.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/pull.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract a single layer/attribute — pull.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") r <- rast(f) # Extract second layer r %>% pull(2) %>% head() #> [1] 229 235 229 229 239 153 # With xy the first two cols are `x` (longitude) and `y` (latitude) r %>% pull(2, xy = TRUE) %>% head() #> [1] 5370160 5370160 5370160 5370160 5370160 5370160 # With renaming r %>% mutate(cat = cut(cyl_tile_3, c(0, 100, 300))) %>% pull(cyl_tile_3, name = cat) %>% head() #> (100,300] (100,300] (100,300] (100,300] (100,300] (100,300] #> 206 224 206 206 233 169"},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract CRS on WKT format — pull_crs","title":"Extract CRS on WKT format — pull_crs","text":"Extract WKT version CRS associated string, number sf/Spat* object. Well-known text (WKT) representation coordinate reference systems (CRS) character string identifies precisely parameters CRS. current standard used sf terra packages.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract CRS on WKT format — pull_crs","text":"","code":"pull_crs(.data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract CRS on WKT format — pull_crs","text":".data Input potentially including representing CRS. sf/sfc object, SpatRaster/SpatVector object, crs object sf::st_crs(), character (example proj4 string) integer (representing EPSG code). ... ignored","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract CRS on WKT format — pull_crs","text":"WKT representation corresponding CRS.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Extract CRS on WKT format — pull_crs","text":"Although WKT representation , sf terra API slightly differs. example, sf can : sf::st_transform(x, 25830) sf equivalent : terra::project(bb, \"epsg:25830\") Knowing WKT help smooth workflows working different packages object types.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"internals","dir":"Reference","previous_headings":"","what":"Internals","title":"Extract CRS on WKT format — pull_crs","text":"thin wrapper sf::st_crs() terra::crs().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/pull_crs.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract CRS on WKT format — pull_crs","text":"","code":"# sf objects sfobj <- sf::st_as_sfc(\"MULTIPOINT ((0 0), (1 1))\", crs = 4326) fromsf1 <- pull_crs(sfobj) fromsf2 <- pull_crs(sf::st_crs(sfobj)) # terra v <- terra::vect(sfobj) r <- terra::rast(v) fromterra1 <- pull_crs(v) fromterra2 <- pull_crs(r) # integers fromint <- pull_crs(4326) # Characters fromchar <- pull_crs(\"epsg:4326\") all( fromsf1 == fromsf2, fromsf2 == fromterra1, fromterra1 == fromterra2, fromterra2 == fromint, fromint == fromchar ) #> [1] TRUE cat(fromsf1) #> GEOGCRS[\"WGS 84\", #> ENSEMBLE[\"World Geodetic System 1984 ensemble\", #> MEMBER[\"World Geodetic System 1984 (Transit)\"], #> MEMBER[\"World Geodetic System 1984 (G730)\"], #> MEMBER[\"World Geodetic System 1984 (G873)\"], #> MEMBER[\"World Geodetic System 1984 (G1150)\"], #> MEMBER[\"World Geodetic System 1984 (G1674)\"], #> MEMBER[\"World Geodetic System 1984 (G1762)\"], #> MEMBER[\"World Geodetic System 1984 (G2139)\"], #> ELLIPSOID[\"WGS 84\",6378137,298.257223563, #> LENGTHUNIT[\"metre\",1]], #> ENSEMBLEACCURACY[2.0]], #> PRIMEM[\"Greenwich\",0, #> ANGLEUNIT[\"degree\",0.0174532925199433]], #> CS[ellipsoidal,2], #> AXIS[\"geodetic latitude (Lat)\",north, #> ORDER[1], #> ANGLEUNIT[\"degree\",0.0174532925199433]], #> AXIS[\"geodetic longitude (Lon)\",east, #> ORDER[2], #> ANGLEUNIT[\"degree\",0.0174532925199433]], #> USAGE[ #> SCOPE[\"Horizontal component of 3D system.\"], #> AREA[\"World.\"], #> BBOX[-90,-180,90,180]], #> ID[\"EPSG\",4326]]"},{"path":"https://dieghernan.github.io/tidyterra/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. dplyr anti_join, arrange, count, distinct, filter, full_join, glimpse, group_by, group_by_drop_default, group_data, group_indices, group_keys, group_rows, group_size, group_vars, groups, groups, inner_join, left_join, mutate, n_groups, pull, relocate, rename, rename_with, right_join, rowwise, select, semi_join, slice, slice_head, slice_max, slice_min, slice_sample, slice_tail, summarise, summarize, tally, transmute, ungroup ggplot2 aes, after_stat, autoplot, fortify tibble as_tibble tidyr drop_na, fill, pivot_longer, pivot_wider, replace_na","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Change layer/attribute order — relocate.Spat","title":"Change layer/attribute order — relocate.Spat","text":"Use relocate() change layer/attribute positions, using syntax select.Spat make easy move blocks layers/attributes .","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Change layer/attribute order — relocate.Spat","text":"","code":"# S3 method for class 'SpatRaster' relocate(.data, ..., .before = NULL, .after = NULL) # S3 method for class 'SpatVector' relocate(.data, ..., .before = NULL, .after = NULL)"},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Change layer/attribute order — relocate.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... layers/attributes move. ., . Destination layers/attributes selected .... Supplying neither move layers/attributes left-hand side; specifying error.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Change layer/attribute order — relocate.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Change layer/attribute order — relocate.Spat","text":"terra::subset(data, c(\"name_layer\", \"name_other_layer\"))","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Change layer/attribute order — relocate.Spat","text":"Implementation generic dplyr::relocate() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Change layer/attribute order — relocate.Spat","text":"Relocate layers SpatRaster.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Change layer/attribute order — relocate.Spat","text":"result SpatVector attributes different order.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/relocate.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Change layer/attribute order — relocate.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") spatrast <- rast(f) %>% mutate(aa = 1, bb = 2, cc = 3) names(spatrast) #> [1] \"cyl_tile_1\" \"cyl_tile_2\" \"cyl_tile_3\" \"aa\" \"bb\" #> [6] \"cc\" spatrast %>% relocate(bb, .before = cyl_tile_3) %>% relocate(cyl_tile_1, .after = last_col()) #> class : SpatRaster #> dimensions : 212, 261, 6 (nrow, ncol, nlyr) #> resolution : 2445.985, 2445.985 (x, y) #> extent : -812067, -173664.9, 4852834, 5371383 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : cyl_tile_2, bb, cyl_tile_3, aa, cc, cyl_tile_1 #> min values : 35, 2, 35, 1, 3, 35 #> max values : 251, 2, 250, 1, 3, 253"},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Rename layers/attributes — rename.Spat","title":"Rename layers/attributes — rename.Spat","text":"rename() changes names individual layers/attributes using new_name = old_name syntax; rename_with() renames layers/attributes using function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Rename layers/attributes — rename.Spat","text":"","code":"# S3 method for class 'SpatRaster' rename(.data, ...) # S3 method for class 'SpatRaster' rename_with(.data, .fn, .cols = everything(), ...) # S3 method for class 'SpatVector' rename(.data, ...) # S3 method for class 'SpatVector' rename_with(.data, .fn, .cols = everything(), ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Rename layers/attributes — rename.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... Depending function: rename.Spat*(): . Use new_name = old_name rename selected variables. rename_with(): additional arguments passed onto .fn. .fn function used transform selected .cols. return character vector length input. .cols Columns rename; defaults columns.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Rename layers/attributes — rename.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Rename layers/attributes — rename.Spat","text":"names(Spat*) <- c(\"\", \"b\", \"c\")","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Rename layers/attributes — rename.Spat","text":"Implementation generic dplyr::rename() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Rename layers/attributes — rename.Spat","text":"Rename layers SpatRaster.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Rename layers/attributes — rename.Spat","text":"result SpatVector renamed attributes function call.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/rename.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Rename layers/attributes — rename.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") spatrast <- rast(f) %>% mutate(aa = 1, bb = 2, cc = 3) spatrast #> class : SpatRaster #> dimensions : 212, 261, 6 (nrow, ncol, nlyr) #> resolution : 2445.985, 2445.985 (x, y) #> extent : -812067, -173664.9, 4852834, 5371383 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : cyl_tile_1, cyl_tile_2, cyl_tile_3, aa, bb, cc #> min values : 35, 35, 35, 1, 2, 3 #> max values : 253, 251, 250, 1, 2, 3 spatrast %>% rename( this_first = cyl_tile_1, this_second = cyl_tile_2 ) #> class : SpatRaster #> dimensions : 212, 261, 6 (nrow, ncol, nlyr) #> resolution : 2445.985, 2445.985 (x, y) #> extent : -812067, -173664.9, 4852834, 5371383 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : this_first, this_second, cyl_tile_3, aa, bb, cc #> min values : 35, 35, 35, 1, 2, 3 #> max values : 253, 251, 250, 1, 2, 3 spatrast %>% rename_with( toupper, .cols = starts_with(\"c\") ) #> class : SpatRaster #> dimensions : 212, 261, 6 (nrow, ncol, nlyr) #> resolution : 2445.985, 2445.985 (x, y) #> extent : -812067, -173664.9, 4852834, 5371383 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : CYL_TILE_1, CYL_TILE_2, CYL_TILE_3, aa, bb, CC #> min values : 35, 35, 35, 1, 2, 3 #> max values : 253, 251, 250, 1, 2, 3"},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Replace NAs with specified values — replace_na.Spat","title":"Replace NAs with specified values — replace_na.Spat","text":"Replace NA values layers/attributes specified values","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Replace NAs with specified values — replace_na.Spat","text":"","code":"# S3 method for class 'SpatRaster' replace_na(data, replace = list(), ...) # S3 method for class 'SpatVector' replace_na(data, replace, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Replace NAs with specified values — replace_na.Spat","text":"data SpatRaster created terra::rast() SpatVector created terra::vect(). replace list values, one value layer/attribute NA values replaced. ... Ignored","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Replace NAs with specified values — replace_na.Spat","text":"Spat* object class data. Geometries spatial attributes preserved.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Replace NAs with specified values — replace_na.Spat","text":"Use r[.na(r)] <- ","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/replace_na.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Replace NAs with specified values — replace_na.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) r %>% plot() r %>% replace_na(list(tavg_04 = 6, tavg_06 = 20)) %>% plot()"},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Group SpatVector objects by rows — rowwise.SpatVector","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"rowwise() allows compute SpatVector row---time. useful vectorised function exist. dplyr verbs implementation tidyterra preserve row-wise grouping, exception summarise.SpatVector(). can explicitly ungroup ungroup.SpatVector() as_tibble(), convert grouped SpatVector group_by.SpatVector().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"","code":"# S3 method for class 'SpatVector' rowwise(data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"data SpatVector object. See Methods. ... Variables preserved calling summarise.SpatVector(). typically set variables whose combination uniquely identify row. See dplyr::rowwise().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"SpatVector object additional attribute.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"See Details dplyr::rowwise().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"Implementation generic dplyr::rowwise() function SpatVector objects. mixing terra dplyr syntax row-wise SpatVector (.e, subsetting SpatVector like v[1:3,1:2]) groups attribute can corrupted. tidyterra try re-generate SpatVector. triggered next time use dplyr verb SpatVector. Note also operations (terra::spatSample()) create new SpatVector. cases, result preserve groups attribute. Use rowwise.SpatVector() re-group.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/rowwise.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Group SpatVector objects by rows — rowwise.SpatVector","text":"","code":"library(terra) library(dplyr) v <- terra::vect(system.file(\"shape/nc.shp\", package = \"sf\")) # Select new births nb <- v %>% select(starts_with(\"NWBIR\")) %>% glimpse() #> # A SpatVector 100 x 2 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat NAD27 (EPSG:4267) #> # Extent (x / y) : ([84° 19' 25.87\" W / 75° 27' 25.12\" W] , [33° 52' 55.17\" N / 36° 35' 22.74\" N]) #> #> $ NWBIR74 10, 10, 208, 123, 1066, 954, 115, 254, 748, 160, 550, 1243, 93… #> $ NWBIR79 19, 12, 260, 145, 1197, 1237, 139, 371, 844, 176, 597, 1369, 1… # Compute the mean of NWBIR on each geometry nb %>% rowwise() %>% mutate(nb_mean = mean(c(NWBIR74, NWBIR79))) #> class : SpatVector #> geometry : polygons #> dimensions : 100, 3 (geometries, attributes) #> extent : -84.32385, -75.45698, 33.88199, 36.58965 (xmin, xmax, ymin, ymax) #> source : nc.shp #> coord. ref. : lon/lat NAD27 (EPSG:4267) #> names : NWBIR74 NWBIR79 nb_mean #> type : #> values : 10 19 14.5 #> 10 12 11 #> 208 260 234 # Additional examples # \\donttest{ # use c_across() to more easily select many variables nb %>% rowwise() %>% mutate(m = mean(c_across(NWBIR74:NWBIR79))) #> class : SpatVector #> geometry : polygons #> dimensions : 100, 3 (geometries, attributes) #> extent : -84.32385, -75.45698, 33.88199, 36.58965 (xmin, xmax, ymin, ymax) #> source : nc.shp #> coord. ref. : lon/lat NAD27 (EPSG:4267) #> names : NWBIR74 NWBIR79 m #> type : #> values : 10 19 14.5 #> 10 12 11 #> 208 260 234 # Compute the minimum of x and y in each row nb %>% rowwise() %>% mutate(min = min(c_across(NWBIR74:NWBIR79))) #> class : SpatVector #> geometry : polygons #> dimensions : 100, 3 (geometries, attributes) #> extent : -84.32385, -75.45698, 33.88199, 36.58965 (xmin, xmax, ymin, ymax) #> source : nc.shp #> coord. ref. : lon/lat NAD27 (EPSG:4267) #> names : NWBIR74 NWBIR79 min #> type : #> values : 10 19 10 #> 10 12 10 #> 208 260 208 # Summarising v %>% rowwise() %>% summarise(mean_bir = mean(BIR74, BIR79)) %>% glimpse() %>% autoplot(aes(fill = mean_bir)) #> # A SpatVector 100 x 1 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat NAD27 (EPSG:4267) #> # Extent (x / y) : ([84° 19' 25.87\" W / 75° 27' 25.12\" W] , [33° 52' 55.17\" N / 36° 35' 22.74\" N]) #> #> $ mean_bir 1091, 487, 3188, 508, 1421, 1452, 286, 420, 968, 1612, 1035, … # Supply a variable to be kept v %>% mutate(id2 = as.integer(CNTY_ID / 100)) %>% rowwise(id2) %>% summarise(mean_bir = mean(BIR74, BIR79)) %>% glimpse() %>% autoplot(aes(fill = as.factor(id2))) #> # A SpatVector 100 x 2 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat NAD27 (EPSG:4267) #> # Extent (x / y) : ([84° 19' 25.87\" W / 75° 27' 25.12\" W] , [33° 52' 55.17\" N / 36° 35' 22.74\" N]) #> #> Groups: id2 [2] #> $ id2 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 1… #> $ mean_bir 1091, 487, 3188, 508, 1421, 1452, 286, 420, 968, 1612, 1035, … # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_coltab.html","id":null,"dir":"Reference","previous_headings":"","what":"Discrete scales based in the color table of a SpatRaster — scale_coltab","title":"Discrete scales based in the color table of a SpatRaster — scale_coltab","text":"categorical SpatRaster objects may associated color table. function extract values. functions generates scales vector colors based color table terra::coltab() associated SpatRaster. can also get vector colors named corresponding factor get_coltab_pal(). Additional parameters ... passed ggplot2::discrete_scale(). Note tidyterra just documents selection additional parameters, check ggplot2::discrete_scale() see full range parameters accepted.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_coltab.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Discrete scales based in the color table of a SpatRaster — scale_coltab","text":"","code":"scale_fill_coltab( data, ..., alpha = 1, na.translate = FALSE, na.value = \"transparent\", drop = TRUE ) scale_colour_coltab( data, ..., alpha = 1, na.translate = FALSE, na.value = \"transparent\", drop = TRUE ) get_coltab_pal(x)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_coltab.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Discrete scales based in the color table of a SpatRaster — scale_coltab","text":"data, x SpatRaster one several color tables. See terra::.colors(). ... Arguments passed ggplot2::discrete_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. limits One : NULL use default scale values character vector defines possible values scale order function accepts existing (automatic) values returns new ones. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. alpha alpha transparency, number [0,1], see argument alpha hsv. na.translate NA values removed legend? Default TRUE. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. drop unused factor levels omitted scale? default (TRUE) removes unused factors.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_coltab.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Discrete scales based in the color table of a SpatRaster — scale_coltab","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_coltab.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Discrete scales based in the color table of a SpatRaster — scale_coltab","text":"","code":"library(terra) # Geological Eras # Spanish Geological Survey (IGME) r <- rast(system.file(\"extdata/cyl_era.tif\", package = \"tidyterra\")) plot(r) # Get coltab coltab_pal <- get_coltab_pal(r) coltab_pal #> Precambric-Paleozoic Paleozoic Paleozoic-Mesozoic #> \"#FFBFE9\" \"#9ADDCF\" \"#D79EBD\" #> Mesozoic Mesozoic-Cenozoic Cenozoic #> \"#A4FF74\" \"#FFD480\" \"#FFFFBF\" #> Undetermined #> \"#FFFFFF\" # \\donttest{ # With ggplot2 + tidyterra library(ggplot2) gg <- ggplot() + geom_spatraster(data = r) # Default plot gg # With coltabs gg + scale_fill_coltab(data = r) #> Scale for fill is already present. #> Adding another scale for fill, which will replace the existing scale. # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":null,"dir":"Reference","previous_headings":"","what":"Cross blended hypsometric tints scales — scale_cross_blended","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"Implementation cross blended hypsometric gradients presented doi:10.14714/CP69.20 . following fill scales palettes provided: scale_*_cross_blended_d(): discrete values. scale_*_cross_blended_c(): continuous values. scale_*_cross_blended_b(): binning continuous values. cross_blended.colors(): gradient color palette. See also grDevices::terrain.colors() details. additional set scales provided. scales can act hypsometric (bathymetric) tints. scale_*_cross_blended_tint_d(): discrete values. scale_*_cross_blended_tint_c(): continuous values. scale_*_cross_blended_tint_b(): binning continuous values. cross_blended.colors2(): gradient color palette. See also grDevices::terrain.colors() details. See Details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"","code":"scale_fill_cross_blended_d( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_cross_blended_d( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_cross_blended_c( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_cross_blended_c( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_cross_blended_b( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_cross_blended_b( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) cross_blended.colors(n, palette = \"cold_humid\", alpha = 1, rev = FALSE) scale_fill_cross_blended_tint_d( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_cross_blended_tint_d( palette = \"cold_humid\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_cross_blended_tint_c( palette = \"cold_humid\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_cross_blended_tint_c( palette = \"cold_humid\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_cross_blended_tint_b( palette = \"cold_humid\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_cross_blended_tint_b( palette = \"cold_humid\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"coloursteps\" ) cross_blended.colors2(n, palette = \"cold_humid\", alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"Patterson, T., & Jenny, B. (2011). Development Rationale Cross-blended Hypsometric Tints. Cartographic Perspectives, (69), 31 - 46. doi:10.14714/CP69.20 . Patterson, T. (2004). Using Cross-blended Hypsometric Tints Generalized Environmental Mapping. Accessed June 10, 2022. https://www.shadedrelief.com/hypso/hypso.html","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"palette valid palette name. name matched list available palettes, ignoring upper vs. lower case. See cross_blended_hypsometric_tints_db info. Values available : \"arid\", \"cold_humid\", \"polar\", \"warm_humid\". ... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed. values colours evenly positioned along gradient vector gives position (0 1) colour colours vector. See rescale() convenience function map arbitrary range 0 1. limits One : NULL use default scale range numeric vector length two providing limits scale. Use NA refer existing minimum maximum function accepts existing (automatic) limits returns new limits. Also accepts rlang lambda function notation. Note setting limits positional scales remove data outside limits. purpose zoom, use limit argument coordinate system (see coord_cartesian()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"scale_*_cross_blended_tint_* palettes, position gradients limits palette redefined. Instead treating color palette continuous gradient, rescaled act hypsometric tint. rough description tints : Blue colors: Negative values. Green colors: 0 1.000 values. Browns: 1000 4.000 values. Whites: Values higher 4.000. following orientation vary depending palette definition (see cross_blended_hypsometric_tints_db example achieved). Note setup palette may always suitable specific data. example, SpatRaster small parts globe (limited range elevations) may well represented. example, SpatRaster range values [100, 200] appear almost uniform color. adjusted using limits/values parameters. cross_blended.colors2() provides gradient color palette distance colors different depending type color. contrast, cross_blended.colors() provides uniform gradient across colors. See Examples.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_cross_blended.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Cross blended hypsometric tints scales — scale_cross_blended","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = cross_blended.colors(100, palette = \"arid\")) # Palette with uneven colors plot(volcano2_rast, col = cross_blended.colors2(100, palette = \"arid\")) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_cross_blended_c(palette = \"cold_humid\") # Use hypsometric tint version... ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_cross_blended_tint_c(palette = \"cold_humid\") # ...but not suitable for the range of the raster: adjust my_lims <- minmax(volcano2_rast) %>% as.integer() + c(-2, 2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_cross_blended_tint_c( palette = \"cold_humid\", limits = my_lims ) # Full map with true tints f_asia <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") asia <- rast(f_asia) ggplot() + geom_spatraster(data = asia) + scale_fill_cross_blended_tint_c( palette = \"warm_humid\", labels = scales::label_number(), breaks = c(-10000, 0, 5000, 8000), guide = guide_colorbar(reverse = TRUE) ) + labs(fill = \"elevation (m)\") + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" ) # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_cross_blended_b(breaks = seq(70, 200, 25), palette = \"arid\") # With limits and breaks ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_cross_blended_tint_b( breaks = seq(75, 200, 25), palette = \"arid\", limits = my_lims ) # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_cross_blended_d(na.value = \"gray10\", palette = \"cold_humid\") # Tint version ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_cross_blended_tint_d( na.value = \"gray10\", palette = \"cold_humid\" ) # } # Display all the cross-blended palettes pals <- unique(cross_blended_hypsometric_tints_db$pal) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = cross_blended.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar) # Display all the cross-blended palettes on version 2 pals <- unique(cross_blended_hypsometric_tints_db$pal) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = cross_blended.colors2(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":null,"dir":"Reference","previous_headings":"","what":"GRASS scales — scale_grass","title":"GRASS scales — scale_grass","text":"Implementation GRASS color tables. following fill scales palettes provided: scale_*_grass_d(): discrete values. scale_*_grass_c(): continuous values. scale_*_grass_b(): binning continuous values. grass.colors(): Gradient color palette. See also grDevices::terrain.colors() details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales. palettes implementation terra::map.pal(), default color palettes provided terra::plot() (terra > 1.7.78).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"GRASS scales — scale_grass","text":"","code":"scale_fill_grass_d( palette = \"viridis\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_grass_d( palette = \"viridis\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_grass_c( palette = \"viridis\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, use_grass_range = TRUE, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_grass_c( palette = \"viridis\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, use_grass_range = TRUE, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_grass_b( palette = \"viridis\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, use_grass_range = TRUE, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_grass_b( palette = \"viridis\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, use_grass_range = TRUE, na.value = \"transparent\", guide = \"coloursteps\" ) grass.colors(n, palette = \"viridis\", alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"GRASS scales — scale_grass","text":"Derived https://github.com/OSGeo/grass/tree/main/lib/gis/colors. See also r.color - GRASS GIS Manual.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"GRASS scales — scale_grass","text":"palette valid palette name. name matched list available palettes, ignoring upper vs. lower case. See grass_db info. ... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. values colours evenly positioned along gradient vector gives position (0 1) colour colours vector. See rescale() convenience function map arbitrary range 0 1. limits One : NULL use default scale range numeric vector length two providing limits scale. Use NA refer existing minimum maximum function accepts existing (automatic) limits returns new limits. Also accepts rlang lambda function notation. Note setting limits positional scales remove data outside limits. purpose zoom, use limit argument coordinate system (see coord_cartesian()). use_grass_range Logical. scale use suggested range plotting? See Details. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"GRASS scales — scale_grass","text":"corresponding ggplot2 layer values applied fill/colour aes().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"GRASS scales — scale_grass","text":"palettes mapped default specific range values (see grass_db). However, possible modify behaviour use_grass_range argument, FALSE color scales mapped range values color/fill aesthethics, See Examples.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"GRASS scales — scale_grass","text":"terra::map.pal()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"GRASS scales — scale_grass","text":"GRASS Development Team (2024). Geographic Resources Analysis Support System (GRASS) Software, Version 8.3.2. Open Source Geospatial Foundation, USA. https://grass.osgeo.org.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_grass.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"GRASS scales — scale_grass","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = grass.colors(100, palette = \"haxby\")) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_grass_c(palette = \"terrain\") # Use with no default limits ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_grass_c(palette = \"terrain\", use_grass_range = FALSE) # Full map with true tints f_asia <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") asia <- rast(f_asia) ggplot() + geom_spatraster(data = asia) + scale_fill_grass_c( palette = \"srtm_plus\", labels = scales::label_number(), breaks = c(-10000, 0, 5000, 8000), guide = guide_colorbar(reverse = FALSE) ) + labs(fill = \"elevation (m)\") + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" ) # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_grass_b(breaks = seq(70, 200, 25), palette = \"sepia\") # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_grass_d(palette = \"soilmoisture\") # } # Display all the GRASS palettes data(\"grass_db\") pals_all <- unique(grass_db$pal) # In batches pals <- pals_all[c(1:25)] # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = grass.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar) # Second batch pals <- pals_all[-c(1:25)] ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = grass.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":null,"dir":"Reference","previous_headings":"","what":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"Implementation selection gradient palettes available cpt-city. following scales palettes provided: scale_*_hypso_d(): discrete values. scale_*_hypso_c(): continuous values. scale_*_hypso_b(): binning continuous values. hypso.colors(): gradient color palette. See also grDevices::terrain.colors() details. additional set scales provided. scales can act hypsometric (bathymetric) tints. scale_*_hypso_tint_d(): discrete values. scale_*_hypso_tint_c(): continuous values. scale_*_hypso_tint_b(): binning continuous values. hypso.colors2(): gradient color palette. See also grDevices::terrain.colors() details. See Details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"","code":"scale_fill_hypso_d( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_hypso_d( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_hypso_c( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_hypso_c( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_hypso_b( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_hypso_b( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) hypso.colors(n, palette = \"etopo1_hypso\", alpha = 1, rev = FALSE) scale_fill_hypso_tint_d( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_hypso_tint_d( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_hypso_tint_c( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_hypso_tint_c( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_hypso_tint_b( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_hypso_tint_b( palette = \"etopo1_hypso\", ..., alpha = 1, direction = 1, values = NULL, limits = NULL, na.value = \"transparent\", guide = \"coloursteps\" ) hypso.colors2(n, palette = \"etopo1_hypso\", alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"cpt-city: http://seaviewsensing.com/pub/cpt-city/.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"palette valid palette name. name matched list available palettes, ignoring upper vs. lower case. See hypsometric_tints_db info. Values available : \"arctic\", \"arctic_bathy\", \"arctic_hypso\", \"c3t1\", \"colombia\", \"colombia_bathy\", \"colombia_hypso\", \"dem_poster\", \"dem_print\", \"dem_screen\", \"etopo1\", \"etopo1_bathy\", \"etopo1_hypso\", \"gmt_globe\", \"gmt_globe_bathy\", \"gmt_globe_hypso\", \"meyers\", \"meyers_bathy\", \"meyers_hypso\", \"moon\", \"moon_bathy\", \"moon_hypso\", \"nordisk-familjebok\", \"nordisk-familjebok_bathy\", \"nordisk-familjebok_hypso\", \"pakistan\", \"spain\", \"usgs-gswa2\", \"utah_1\", \"wiki-2.0\", \"wiki-2.0_bathy\", \"wiki-2.0_hypso\", \"wiki-schwarzwald-cont\". ... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed. values colours evenly positioned along gradient vector gives position (0 1) colour colours vector. See rescale() convenience function map arbitrary range 0 1. limits One : NULL use default scale range numeric vector length two providing limits scale. Use NA refer existing minimum maximum function accepts existing (automatic) limits returns new limits. Also accepts rlang lambda function notation. Note setting limits positional scales remove data outside limits. purpose zoom, use limit argument coordinate system (see coord_cartesian()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"scale_*_hypso_tint_* palettes, position gradients limits palette redefined. Instead treating color palette continuous gradient, rescaled act hypsometric tint. rough description tints : Blue colors: Negative values. Green colors: 0 1.000 values. Browns: 1000 4.000 values. Whites: Values higher 4.000. following orientation vary depending palette definition (see hypsometric_tints_db example achieved). Note setup palette may always suitable specific data. example, SpatRaster small parts globe (limited range elevations) may well represented. example, SpatRaster range values [100, 200] appear almost uniform color. adjusted using limits/values parameters. hypso.colors2() provides gradient color palette distance colors different depending type color. contrast, hypso.colors() provides uniform gradient across colors. See Examples.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_hypso.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Gradient scales for representing hypsometry and bathymetry — scale_hypso","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = hypso.colors(100, palette = \"wiki-2.0_hypso\")) # Palette with uneven colors plot(volcano2_rast, col = hypso.colors2(100, palette = \"wiki-2.0_hypso\")) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_hypso_c(palette = \"colombia_hypso\") # Use hypsometric tint version... ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_hypso_tint_c(palette = \"colombia_hypso\") # ...but not suitable for the range of the raster: adjust my_lims <- minmax(volcano2_rast) %>% as.integer() + c(-2, 2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_hypso_tint_c( palette = \"colombia_hypso\", limits = my_lims ) # Full map with true tints f_asia <- system.file(\"extdata/asia.tif\", package = \"tidyterra\") asia <- rast(f_asia) ggplot() + geom_spatraster(data = asia) + scale_fill_hypso_tint_c( palette = \"etopo1\", labels = scales::label_number(), breaks = c(-10000, 0, 5000, 8000), guide = guide_colorbar(reverse = TRUE) ) + labs(fill = \"elevation (m)\") + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" ) # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_hypso_b(breaks = seq(70, 200, 25), palette = \"wiki-2.0_hypso\") # With limits and breaks ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_hypso_tint_b( breaks = seq(75, 200, 25), palette = \"wiki-2.0_hypso\", limits = my_lims ) # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_hypso_d(na.value = \"gray10\", palette = \"dem_poster\") # Tint version ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_hypso_tint_d(na.value = \"gray10\", palette = \"dem_poster\") # } # Display all the cpl_city palettes pals <- unique(hypsometric_tints_db$pal) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = hypso.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar) # Display all the cpl_city palettes on version 2 pals <- unique(hypsometric_tints_db$pal) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = hypso.colors2(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":null,"dir":"Reference","previous_headings":"","what":"Gradient scales from princess color schemes — scale_princess","title":"Gradient scales from princess color schemes — scale_princess","text":"Implementation gradient palettes presented https://leahsmyth.github.io/Princess-Colour-Schemes/index.html. Three scales provided: scale_*_princess_d(): discrete values. scale_*_princess_c(): continuous values. scale_*_princess_b(): binning continuous values. Additionally, color palette princess.colors() provided. See also grDevices::terrain.colors() details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Gradient scales from princess color schemes — scale_princess","text":"","code":"scale_fill_princess_d( palette = \"snow\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_princess_d( palette = \"snow\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_princess_c( palette = \"snow\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_princess_c( palette = \"snow\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_princess_b( palette = \"snow\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_princess_b( palette = \"snow\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) princess.colors(n, palette = \"snow\", alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Gradient scales from princess color schemes — scale_princess","text":"https://github.com/LeahSmyth/Princess-Colour-Schemes.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Gradient scales from princess color schemes — scale_princess","text":"palette valid palette name. name matched list available palettes, ignoring upper vs. lower case. Values available : \"snow\", \"ella\", \"bell\", \"aura\", \"denmark\", \"france\", \"arabia\", \"america\", \"asia\", \"neworleans\", \"punz\", \"scotland\", \"cold\", \"norge\", \"maori\". ... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. limits One : NULL use default scale values character vector defines possible values scale order function accepts existing (automatic) values returns new ones. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Gradient scales from princess color schemes — scale_princess","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_princess.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Gradient scales from princess color schemes — scale_princess","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = princess.colors(100)) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_princess_c() # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_princess_b(breaks = seq(70, 200, 10), palette = \"denmark\") # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_princess_d(na.value = \"gray10\", palette = \"maori\") # } # Display all the princess palettes pals <- unique(princess_db$pal) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = princess.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_terrain.html","id":null,"dir":"Reference","previous_headings":"","what":"Terrain colour scales from grDevices — scale_terrain","title":"Terrain colour scales from grDevices — scale_terrain","text":"Implementation classic color palette terrain.colors(): scale_*_terrain_d(): discrete values. scale_*_terrain_c(): continuous values. scale_*_terrain_b(): binning continuous values. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_terrain.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Terrain colour scales from grDevices — scale_terrain","text":"","code":"scale_fill_terrain_d( ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_terrain_d( ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_terrain_c( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_terrain_c( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_terrain_b( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_terrain_b( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" )"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_terrain.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Terrain colour scales from grDevices — scale_terrain","text":"... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. limits One : NULL use default scale values character vector defines possible values scale order function accepts existing (automatic) values returns new ones. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_terrain.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Terrain colour scales from grDevices — scale_terrain","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_terrain.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Terrain colour scales from grDevices — scale_terrain","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_terrain_c() # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_terrain_b(breaks = seq(70, 200, 10)) # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_terrain_d(na.value = \"gray10\") # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":null,"dir":"Reference","previous_headings":"","what":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"Implementation gradient palettes provided WhiteboxTools. Three scales provided: scale_*_whitebox_d(): discrete values. scale_*_whitebox_c(): continuous values. scale_*_whitebox_b(): binning continuous values. Additionally, color palette whitebox.colors() provided. See also grDevices::terrain.colors() details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"","code":"scale_fill_whitebox_d( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_whitebox_d( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_whitebox_c( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_whitebox_c( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_whitebox_b( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_whitebox_b( palette = \"high_relief\", ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) whitebox.colors(n, palette = \"high_relief\", alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"https://github.com/jblindsay/whitebox-tools, MIT License. Copyright (c) 2017-2021 John Lindsay.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"palette valid palette name. name matched list available palettes, ignoring upper vs. lower case. Values available : \"atlas\", \"high_relief\", \"arid\", \"soft\", \"muted\", \"purple\", \"viridi\", \"gn_yl\", \"pi_y_g\", \"bl_yl_rd\", \"deep\". ... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. limits One : NULL use default scale values character vector defines possible values scale order function accepts existing (automatic) values returns new ones. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. na.translate NA values removed legend? Default TRUE. drop unused factor levels omitted scale? default (TRUE) removes unused factors. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_whitebox.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Gradient scales from WhiteboxTools color schemes — scale_whitebox","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = whitebox.colors(100)) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_whitebox_c() # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_whitebox_b(breaks = seq(70, 200, 10), palette = \"atlas\") # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_whitebox_d(na.value = \"gray10\", palette = \"soft\") # } # Display all the whitebox palettes pals <- c( \"atlas\", \"high_relief\", \"arid\", \"soft\", \"muted\", \"purple\", \"viridi\", \"gn_yl\", \"pi_y_g\", \"bl_yl_rd\", \"deep\" ) # Helper fun for plotting ncols <- 128 rowcol <- grDevices::n2mfrow(length(pals)) opar <- par(no.readonly = TRUE) par(mfrow = rowcol, mar = rep(1, 4)) for (i in pals) { image( x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), col = whitebox.colors(ncols, i), main = i, ylab = \"\", xaxt = \"n\", yaxt = \"n\", bty = \"n\" ) } par(opar)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_wiki.html","id":null,"dir":"Reference","previous_headings":"","what":"Gradient scales from Wikipedia color schemes — scale_color_coltab","title":"Gradient scales from Wikipedia color schemes — scale_color_coltab","text":"Implementation based Wikipedia Colorimetric conventions topographic maps. Three scales provided: scale_*_wiki_d(): discrete values. scale_*_wiki_c(): continuous values. scale_*_wiki_b(): binning continuous values. Additionally, color palette wiki.colors() provided. See also grDevices::terrain.colors() details. Additional parameters ... passed : Discrete values: ggplot2::discrete_scale(). Continuous values: ggplot2::continuous_scale(). Binned continuous values: ggplot2::binned_scale(). Note tidyterra just documents selection additional parameters, check ggplot2 functions listed see full range parameters accepted scales.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_wiki.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Gradient scales from Wikipedia color schemes — scale_color_coltab","text":"","code":"scale_fill_wiki_d( ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_colour_wiki_d( ..., alpha = 1, direction = 1, na.translate = FALSE, drop = TRUE ) scale_fill_wiki_c( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_colour_wiki_c( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"colourbar\" ) scale_fill_wiki_b( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) scale_colour_wiki_b( ..., alpha = 1, direction = 1, na.value = \"transparent\", guide = \"coloursteps\" ) wiki.colors(n, alpha = 1, rev = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_wiki.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Gradient scales from Wikipedia color schemes — scale_color_coltab","text":"... Arguments passed ggplot2::discrete_scale, ggplot2::continuous_scale, ggplot2::binned_scale breaks One : NULL breaks waiver() default breaks (scale limits) character vector breaks function takes limits input returns breaks output. Also accepts rlang lambda function notation. labels One : NULL labels waiver() default labels computed transformation object character vector giving labels (must length breaks) expression vector (must length breaks). See ?plotmath details. function takes breaks input returns labels output. Also accepts rlang lambda function notation. limits One : NULL use default scale values character vector defines possible values scale order function accepts existing (automatic) values returns new ones. Also accepts rlang lambda function notation. expand position scales, vector range expansion constants used add padding around data ensure placed distance away axes. Use convenience function expansion() generate values expand argument. defaults expand scale 5% side continuous variables, 0.6 units side discrete variables. minor_breaks One : NULL minor breaks waiver() default breaks (one minor break major break) numeric vector positions function given limits returns vector minor breaks. Also accepts rlang lambda function notation. function two arguments, given limits major breaks. n.breaks integer guiding number major breaks. algorithm may choose slightly different number ensure nice break labels. effect breaks = waiver(). Use NULL use default number breaks given transformation. nice.breaks Logical. breaks attempted placed nice values instead exactly evenly spaced limits. TRUE (default) scale ask transformation object create breaks, may result different number breaks requested. Ignored breaks given explicitly. alpha alpha transparency, number [0,1], see argument alpha hsv. na.translate NA values removed legend? Default TRUE. na.value Missing values replaced value. default, tidyterra uses na.value = \"transparent\" cells NA filled. See also #120. drop unused factor levels omitted scale? default (TRUE) removes unused factors. direction Sets order colors scale. 1, default, colors ordered darkest lightest. -1, order colors reversed. guide function used create guide name. See guides() information. n number colors (\\(\\ge 1\\)) palette. rev logical indicating whether ordering colors reversed.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_wiki.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Gradient scales from Wikipedia color schemes — scale_color_coltab","text":"corresponding ggplot2 layer values applied fill/colour aesthetics.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/scale_wiki.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Gradient scales from Wikipedia color schemes — scale_color_coltab","text":"","code":"# \\donttest{ filepath <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") library(terra) volcano2_rast <- rast(filepath) # Palette plot(volcano2_rast, col = wiki.colors(100)) library(ggplot2) ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_wiki_c() # Binned ggplot() + geom_spatraster(data = volcano2_rast) + scale_fill_wiki_b(breaks = seq(70, 200, 10)) # With discrete values factor <- volcano2_rast %>% mutate(cats = cut(elevation, breaks = c(100, 120, 130, 150, 170, 200), labels = c( \"Very Low\", \"Low\", \"Average\", \"High\", \"Very High\" ) )) ggplot() + geom_spatraster(data = factor, aes(fill = cats)) + scale_fill_wiki_d(na.value = \"gray10\") # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Subset layers/attributes of Spat* objects — select.Spat","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"Select (optionally rename) attributes/layers Spat* objects, using concise mini-language. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"","code":"# S3 method for class 'SpatRaster' select(.data, ...) # S3 method for class 'SpatVector' select(.data, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Subset layers/attributes of Spat* objects — select.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... One unquoted expressions separated commas. Layer/attribute names can used positions Spat* object, expressions like x:y can used select range layers/attributes.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"terra::subset()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"Implementation generic dplyr::select() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"Select (rename) layers SpatRaster. result SpatRaster extent, resolution crs .data. number (possibly name) layers modified.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"result SpatVector selected (possibly renamed) attributes function call.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/select.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Subset layers/attributes of Spat* objects — select.Spat","text":"","code":"library(terra) # SpatRaster method spatrast <- rast( crs = \"EPSG:3857\", nrows = 10, ncols = 10, extent = c(100, 200, 100, 200), nlyr = 6, vals = seq_len(10 * 10 * 6) ) spatrast %>% select(1) #> class : SpatRaster #> dimensions : 10, 10, 1 (nrow, ncol, nlyr) #> resolution : 10, 10 (x, y) #> extent : 100, 200, 100, 200 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> name : lyr.1 #> min value : 1 #> max value : 100 # By name spatrast %>% select(lyr.1:lyr.4) #> class : SpatRaster #> dimensions : 10, 10, 4 (nrow, ncol, nlyr) #> resolution : 10, 10 (x, y) #> extent : 100, 200, 100, 200 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : lyr.1, lyr.2, lyr.3, lyr.4 #> min values : 1, 101, 201, 301 #> max values : 100, 200, 300, 400 # Rename spatrast %>% select(a = lyr.1, c = lyr.6) #> class : SpatRaster #> dimensions : 10, 10, 2 (nrow, ncol, nlyr) #> resolution : 10, 10 (x, y) #> extent : 100, 200, 100, 200 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> names : a, c #> min values : 1, 501 #> max values : 100, 600 # SpatVector method f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- vect(f) v #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos #> ES-LE 24 Leon v %>% select(1, 3) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 2 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 name #> type : #> values : ES-AV Avila #> ES-BU Burgos #> ES-LE Leon v %>% select(iso2, name2 = cpro) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 2 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 name2 #> type : #> values : ES-AV 05 #> ES-BU 09 #> ES-LE 24"},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Subset cells/rows/columns/geometries using their positions — slice.Spat","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"slice() methods lets index cells/rows/columns/geometries (integer) locations. allows select, remove, duplicate dimensions Spat* object. want slice SpatRaster geographic coordinates use filter.SpatRaster() method. accompanied number helpers common use cases: slice_head() slice_tail() select first last cells/geometries. slice_sample() randomly selects cells/geometries. slice_rows() slice_cols() allow subset entire rows columns, SpatRaster. slice_colrows() subsets regions SpatRaster row column position SpatRaster. can get skeleton SpatRaster cell, column row index as_coordinates(). See Methods details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"","code":"# S3 method for class 'SpatRaster' slice(.data, ..., .preserve = FALSE, .keep_extent = FALSE) # S3 method for class 'SpatVector' slice(.data, ..., .preserve = FALSE) # S3 method for class 'SpatRaster' slice_head(.data, ..., n, prop, .keep_extent = FALSE) # S3 method for class 'SpatVector' slice_head(.data, ..., n, prop) # S3 method for class 'SpatRaster' slice_tail(.data, ..., n, prop, .keep_extent = FALSE) # S3 method for class 'SpatVector' slice_tail(.data, ..., n, prop) # S3 method for class 'SpatRaster' slice_min( .data, order_by, ..., n, prop, with_ties = TRUE, .keep_extent = FALSE, na.rm = TRUE ) # S3 method for class 'SpatVector' slice_min(.data, order_by, ..., n, prop, with_ties = TRUE, na_rm = FALSE) # S3 method for class 'SpatRaster' slice_max( .data, order_by, ..., n, prop, with_ties = TRUE, .keep_extent = FALSE, na.rm = TRUE ) # S3 method for class 'SpatVector' slice_max(.data, order_by, ..., n, prop, with_ties = TRUE, na_rm = FALSE) # S3 method for class 'SpatRaster' slice_sample( .data, ..., n, prop, weight_by = NULL, replace = FALSE, .keep_extent = FALSE ) # S3 method for class 'SpatVector' slice_sample(.data, ..., n, prop, weight_by = NULL, replace = FALSE) slice_rows(.data, ...) # S3 method for class 'SpatRaster' slice_rows(.data, ..., .keep_extent = FALSE) slice_cols(.data, ...) # S3 method for class 'SpatRaster' slice_cols(.data, ..., .keep_extent = FALSE) slice_colrows(.data, ...) # S3 method for class 'SpatRaster' slice_colrows(.data, ..., cols, rows, .keep_extent = FALSE, inverse = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":".data SpatRaster created terra::rast() SpatVector created terra::vect(). ... Integer row values. Provide either positive values keep, negative values drop. values provided must either positive negative. Indices beyond number rows input silently ignored. See Methods. .preserve Ignored Spat* objects. .keep_extent extent resulting SpatRaster kept? See also terra::trim(), terra::extend(). n, prop Provide either n, number rows, prop, proportion rows select. neither supplied, n = 1 used. n greater number rows group (prop > 1), result silently truncated group size. prop rounded towards zero generate integer number rows. negative value n prop subtracted group size. example, n = -2 group 5 rows select 5 - 2 = 3 rows; prop = -0.25 8 rows select 8 * (1 - 0.25) = 6 rows. order_by Variable function variables order . order multiple variables, wrap data frame tibble. with_ties ties kept together? default, TRUE, may return rows request. Use FALSE ignore ties, return first n rows. na.rm Logical, cells present value NA removed computing slice_min()/slice_max()?. default TRUE. na_rm missing values order_by removed result? FALSE, NA values sorted end (like arrange()), included insufficient non-missing values reach n/prop. weight_by Sampling weights. must evaluate vector non-negative numbers length input. Weights automatically standardised sum 1. replace sampling performed (TRUE) without (FALSE, default) replacement. cols, rows Integer col/row values SpatRaster inverse TRUE, .data inverse-masked given selection. See terra::mask().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"Spat* object class .data. See Methods.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"terra::subset(), terra::spatSample()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"Implementation generic dplyr::slice() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"result SpatRaster crs resolution input cell values selected cells/columns/rows preserved. Use .keep_extent = TRUE preserve extent .data output. non-selected cells present value NA.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"result SpatVector attributes selected geometries preserved. .data grouped SpatVector, operation performed group, (e.g.) slice_head(df, n = 5) select first five rows group.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/slice.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Subset cells/rows/columns/geometries using their positions — slice.Spat","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) # Slice first 100 cells r %>% slice(1:100) %>% plot() # Rows r %>% slice_rows(1:30) %>% plot() # Cols r %>% slice_cols(-(20:50)) %>% plot() # Spatial sample r %>% slice_sample(prop = 0.2) %>% plot() # Slice regions r %>% slice_colrows( cols = c(20:40, 60:80), rows = -c(1:20, 30:50) ) %>% plot() # Group wise operation with SpatVectors-------------------------------------- v <- terra::vect(system.file(\"ex/lux.shp\", package = \"terra\")) # \\donttest{ glimpse(v) %>% autoplot(aes(fill = NAME_1)) #> # A SpatVector 12 x 6 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 44' 38.9\" E / 6° 31' 41.71\" E] , [49° 26' 52.11\" N / 50° 10' 53.84\" N]) #> #> $ ID_1 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3 #> $ NAME_1 \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Gr… #> $ ID_2 1, 2, 3, 4, 5, 6, 7, 12, 8, 9, 10, 11 #> $ NAME_2 \"Clervaux\", \"Diekirch\", \"Redange\", \"Vianden\", \"Wiltz\", \"Echtern… #> $ AREA 312, 218, 259, 76, 263, 188, 129, 210, 185, 251, 237, 233 #> $ POP 18081, 32543, 18664, 5163, 16735, 18899, 22366, 29828, 48187, 1… gv <- v %>% group_by(NAME_1) # All slice helpers operate per group, silently truncating to the group size gv %>% slice_head(n = 1) %>% glimpse() %>% autoplot(aes(fill = NAME_1)) #> # A SpatVector 3 x 6 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 49' 34.44\" E / 6° 31' 41.71\" E] , [49° 32' 55.33\" N / 50° 10' 53.84\" N]) #> #> Groups: NAME_1 [3] #> $ ID_1 1, 2, 3 #> $ NAME_1 \"Diekirch\", \"Grevenmacher\", \"Luxembourg\" #> $ ID_2 1, 6, 8 #> $ NAME_2 \"Clervaux\", \"Echternach\", \"Capellen\" #> $ AREA 312, 188, 185 #> $ POP 18081, 18899, 48187 gv %>% slice_tail(n = 1) %>% glimpse() %>% autoplot(aes(fill = NAME_1)) #> # A SpatVector 3 x 6 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 44' 38.9\" E / 6° 30' 59.35\" E] , [49° 35' 13.15\" N / 50° 2' 10.76\" N]) #> #> Groups: NAME_1 [3] #> $ ID_1 1, 2, 3 #> $ NAME_1 \"Diekirch\", \"Grevenmacher\", \"Luxembourg\" #> $ ID_2 5, 12, 11 #> $ NAME_2 \"Wiltz\", \"Grevenmacher\", \"Mersch\" #> $ AREA 263, 210, 233 #> $ POP 16735, 29828, 32112 gv %>% slice_min(AREA, n = 1) %>% glimpse() %>% autoplot(aes(fill = NAME_1)) #> # A SpatVector 3 x 6 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 51' 7.49\" E / 6° 22' 54.12\" E] , [49° 27' 53.95\" N / 49° 59' 2.98\" N]) #> #> Groups: NAME_1 [3] #> $ ID_1 1, 2, 3 #> $ NAME_1 \"Diekirch\", \"Grevenmacher\", \"Luxembourg\" #> $ ID_2 4, 7, 8 #> $ NAME_2 \"Vianden\", \"Remich\", \"Capellen\" #> $ AREA 76, 129, 185 #> $ POP 5163, 22366, 48187 gv %>% slice_max(AREA, n = 1) %>% glimpse() %>% autoplot(aes(fill = NAME_1)) #> # A SpatVector 3 x 6 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 48' 37.74\" E / 6° 30' 59.35\" E] , [49° 26' 52.11\" N / 50° 10' 53.84\" N]) #> #> Groups: NAME_1 [3] #> $ ID_1 1, 2, 3 #> $ NAME_1 \"Diekirch\", \"Grevenmacher\", \"Luxembourg\" #> $ ID_2 1, 12, 9 #> $ NAME_2 \"Clervaux\", \"Grevenmacher\", \"Esch-sur-Alzette\" #> $ AREA 312, 210, 251 #> $ POP 18081, 29828, 176820 # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract coordinates from SpatVector objects — stat_spat_coordinates","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"stat_spat_coordinates() extracts coordinates SpatVector objects summarises one pair coordinates (x y) per geometry.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"","code":"stat_spat_coordinates( mapping = aes(), data = NULL, geom = \"point\", position = \"identity\", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )"},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"mapping Set aesthetic mappings created aes(). specified inherit.aes = TRUE (default), combined default mapping top level plot. must supply mapping plot mapping. data SpatVector object, see terra::vect(). geom geometric object use display data layer. using stat_*() function construct layer, geom argument can used override default coupling stats geoms. geom argument accepts following: Geom ggproto subclass, example GeomPoint. string naming geom. give geom string, strip function name geom_ prefix. example, use geom_point(), give geom \"point\". information ways specify geom, see layer geom documentation. position position adjustment use data layer. can used various ways, including prevent overplotting improving display. position argument accepts following: result calling position function, position_jitter(). method allows passing extra arguments position. string naming position adjustment. give position string, strip function name position_ prefix. example, use position_jitter(), give position \"jitter\". information ways specify position, see layer position documentation. na.rm FALSE, default, missing values removed warning. TRUE, missing values silently removed. show.legend logical. layer included legends? NA, default, includes aesthetics mapped. FALSE never includes, TRUE always includes. can also set one \"polygon\", \"line\", \"point\" override default legend. inherit.aes FALSE, overrides default aesthetics, rather combining . useful helper functions define data aesthetics inherit behaviour default plot specification, e.g. borders(). ... arguments passed ggplot2::stat_sf_coordinates().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"Wrapper ggplot2::stat_sf_coordinates(). See ggplot2::stat_sf_coordinates() details.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/stat_spat_coordinates.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract coordinates from SpatVector objects — stat_spat_coordinates","text":"","code":"# \\donttest{ cyl <- terra::vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) library(ggplot2) ggplot(cyl) + stat_spat_coordinates() ggplot(cyl) + geom_errorbarh( aes( geometry = geometry, xmin = after_stat(x) - 50000, xmax = after_stat(x) + 50000, y = after_stat(y), height = 10000 ), stat = \"sf_coordinates\" ) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"summarise() creates new SpatVector. returns one geometry combination grouping variables; grouping variables, output single geometry summarising observations input combining geometries SpatVector. contain one column grouping variable one column summary statistics specified. summarise.SpatVector() summarize.SpatVector() synonyms","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"","code":"# S3 method for class 'SpatVector' summarise(.data, ..., .by = NULL, .groups = NULL, .dissolve = TRUE) # S3 method for class 'SpatVector' summarize(.data, ..., .by = NULL, .groups = NULL, .dissolve = TRUE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":".data SpatVector. ... Name-value pairs summary functions. name name variable result. value can : vector length 1, e.g. min(x), n(), sum(.na(y)). data frame, add multiple columns single expression. Returning values size 0 >1 deprecated 1.1.0. Please use reframe() instead. .Ignored method ( dplyr). .groups See dplyr::summarise() .dissolve logical. borders aggregated geometries dissolved?","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"terra::aggregate()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"Implementation generic dplyr::summarise() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"Similarly implementation sf function can used dissolve geometries (.dissolve = TRUE) create MULTI versions geometries (.dissolve = FALSE). See Examples.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/summarise.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Summarise each group of a SpatVector down to one geometry — summarise.SpatVector","text":"","code":"library(terra) library(ggplot2) v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) # Grouped gr_v <- v %>% mutate(start_with_s = substr(name, 1, 1) == \"S\") %>% group_by(start_with_s) # Dissolving diss <- gr_v %>% summarise(n = dplyr::n(), mean = mean(as.double(cpro))) diss #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : start_with_s n mean #> type : #> values : FALSE 6 28 #> TRUE 3 39.67 autoplot(diss, aes(fill = start_with_s)) + ggplot2::ggtitle(\"Dissolved\") # Not dissolving no_diss <- gr_v %>% summarise(n = dplyr::n(), mean = mean(as.double(cpro)), .dissolve = FALSE) # Same statistic no_diss #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : start_with_s n mean #> type : #> values : FALSE 6 28 #> TRUE 3 39.67 autoplot(no_diss, aes(fill = start_with_s)) + ggplot2::ggtitle(\"Not Dissolved\")"},{"path":"https://dieghernan.github.io/tidyterra/reference/tidyterra-package.html","id":null,"dir":"Reference","previous_headings":"","what":"tidyterra: 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' Objects — tidyterra-package","title":"tidyterra: 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' Objects — tidyterra-package","text":"Extension 'tidyverse' 'SpatRaster' 'SpatVector' objects 'terra' package. includes also new 'geom_' functions provide convenient way visualizing 'terra' objects 'ggplot2'.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/tidyterra-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"tidyterra: 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' Objects — tidyterra-package","text":"Maintainer: Diego Hernangómez diego.hernangomezherrero@gmail.com (ORCID) [copyright holder] contributors: Dewey Dunnington (ORCID) (ggspatial code) [contributor] ggplot2 authors (contour code) [copyright holder]","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/volcano2.html","id":null,"dir":"Reference","previous_headings":"","what":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","title":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","text":"Probably already know volcano dataset. dataset provides updated information Maungawhau (Mt. Eden) Toitu Te Whenua Land Information New Zealand, Government's agency provides free online access New Zealand’s --date land seabed data.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/volcano2.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","text":"matrix 174 rows 122 columns. value corresponding altitude meters.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/volcano2.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","text":"Auckland LiDAR 1m DEM (2013). DEM LiDAR data Auckland region captured 2013. original data downsampled resolution 5m due disk space constrains. Data License: CC 4.0.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/volcano2.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","text":"Information needed regenerating original SpatRaster file: resolution: c(5, 5) extent: 1756969, 1757579, 5917003, 5917873 (xmin, xmax, ymin, ymax) coord. ref. : NZGD2000 / New Zealand Transverse Mercator 2000 (EPSG:2193)","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/volcano2.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Updated topographic information on Auckland's Maungawhau volcano — volcano2","text":"","code":"data(\"volcano2\") filled.contour(volcano2, color.palette = hypso.colors, asp = 1) title(main = \"volcano2 data: filled contour map\") # Geo-tag # Empty raster volcano2_raster <- terra::rast(volcano2) terra::crs(volcano2_raster) <- pull_crs(2193) terra::ext(volcano2_raster) <- c(1756968, 1757576, 5917000, 5917872) names(volcano2_raster) <- \"volcano2\" library(ggplot2) ggplot() + geom_spatraster(data = volcano2_raster) + scale_fill_hypso_c() + labs( title = \"volcano2 SpatRaster\", subtitle = \"Georeferenced\", fill = \"Elevation (m)\" )"},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-062","dir":"Changelog","previous_headings":"","what":"tidyterra 0.6.2","title":"tidyterra 0.6.2","text":"CRAN release: 2025-01-08 Add (limited) support SpatGraticule (see terra::graticule()) #155. New arguments geom_spatraster_rgb(): stretch zlim. See terra::plotRGB() clarification. geom_spatraster() suggests geom_spatraster_rgb() SpatRaster RGB specification detected (terra::.RGB() TRUE)","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-061","dir":"Changelog","previous_headings":"","what":"tidyterra 0.6.1","title":"tidyterra 0.6.1","text":"CRAN release: 2024-06-08 grass_db scale_fill_grass_c() family. implementation terra::map.pal(), default palette terra::plot() (> 1.7.78). autoplot.SpatRaster() now uses also grass_db default palette. Add scale_fill_princess_c() scale family. Fix tests.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-060","dir":"Changelog","previous_headings":"","what":"tidyterra 0.6.0","title":"tidyterra 0.6.0","text":"CRAN release: 2024-04-22 Requires ggplot2 (>= 3.5.0). pivot_longer.SpatVector() pivot_wider.SpatVector(). fill.SpatVector(). New geom geom_spatraster_contour_text() implemented top isoband::isolines_grob() . glimpse.SpatRaster() glimpse.SpatVector() now displays information using ?tibble::print.tbl_df approach header footer. body still displayed transposed dplyr::glimpse(). See pillar::tbl_format_header() pillar::tbl_format_footer() examples. as_sf() converts SpatVector sf object additional tbl_df class pretty printing. fortify.SpatRaster() gains new argument pivot allows better integration ggplot2 geoms pivoting. wrapper tidyr::pivot_longer(). Tidy documentation. metR added Suggests.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-052","dir":"Changelog","previous_headings":"","what":"tidyterra 0.5.2","title":"tidyterra 0.5.2","text":"CRAN release: 2024-01-19 Adapt tests ggplot2 3.5.0 (#129) @teunbrand. Reduce package size, specially relevant external raster asia.tif.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-051","dir":"Changelog","previous_headings":"","what":"tidyterra 0.5.1","title":"tidyterra 0.5.1","text":"CRAN release: 2023-12-15 Adjust tests as_sf() (#124).","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-050","dir":"Changelog","previous_headings":"","what":"tidyterra 0.5.0","title":"tidyterra 0.5.0","text":"CRAN release: 2023-11-21 tidyterra accepted JOSS. Please use result citation(\"tidyterra\") following string: Hernangómez, D. (2023). “Using tidyverse terra objects: tidyterra package.” Journal Open Source Software, 8(91), 5751. ISSN 2475-9066, https://doi.org/10.21105/joss.05751 changes version: autoplot.SpatRaster() can detect now SpatRaster objects color tables. geom_spatraster() can detect now SpatRaster objects color tables. New scales plotting SpatRaster objects color tables: scale_fill_coltab() rest family scales (colour). tidyverse verbs keeps associated coltab SpatRaster. default discrete scales tidyterra now following setup: na.translate = FALSE. default, non-discrete (e.g. continuous breaks) scales tidyterra now na.value = \"transparent\" (#120). Enhanced glimpse.Spat() meta-information type geometry, crs, etc. New messaging interface thanks cli package.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-041","dir":"Changelog","previous_headings":"","what":"tidyterra 0.4.1","title":"tidyterra 0.4.1","text":"Release JOSS paper. relevant changes.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-040","dir":"Changelog","previous_headings":"","what":"tidyterra 0.4.0","title":"tidyterra 0.4.0","text":"CRAN release: 2023-03-17 glimpse.SpatVector() arrange.SpatVector() distinct.SpatVector() inner_join.SpatVector(), left_join.SpatVector(), right_join.SpatVector() full_join.SpatVector() semi_join.SpatVector() anti_join.SpatVector() summarise.SpatVector() rowwise.SpatVector() group_by.SpatVector(),ungroup.SpatVector() count.SpatVector(), tally.SpatVector() bind_spat_cols(), bind_spat_rows() Already implemented methods now works dplyr::group_by(). Internal review code. Now methods rely sf::st_as_sf() coercion. fact coercion object classes avoided much possible. New glimpse.SpatRaster() method SpatRaster. as_spatvector() as_sf() is_grouped_spatvector()","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-032","dir":"Changelog","previous_headings":"","what":"tidyterra 0.3.2","title":"tidyterra 0.3.2","text":"CRAN release: 2023-02-24 Fix bug pull_crs() returned \"NA\" sf objects field equal NA (#74). Improve docs scales_* (#73) . Remove dependency crayon package (superseded) favor cli. Remove tidyverse Suggests.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-031","dir":"Changelog","previous_headings":"","what":"tidyterra 0.3.1","title":"tidyterra 0.3.1","text":"CRAN release: 2022-11-09 autoplot.SpatRaster() now smarter identifying type plot produce. Can still overridden parameters. Methods fortifying SpatRaster SpatVector objects: fortify.SpatRaster(), fortify.SpatVector(). Three additional palettes included hypso.colors(): \"artic\", \"meyers\" \"nordisk-familjebok\". Added colour scales palettes: scale_colour_*. Remove use ggplot2::aes_string(). Adapt geom_spatraster_contour() geom_spatraster_contour_filled() changes introduced ggplot2 (3.4.0), notably adoption linewidth = .2, default.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-030","dir":"Changelog","previous_headings":"","what":"tidyterra 0.3.0","title":"tidyterra 0.3.0","text":"CRAN release: 2022-10-12 Package back CRAN. Libraries dplyr, tidyr, tibble attached default. Needed functions reexported instead. Now geom_spatraster() possible avoid default fill layer using geom_spatraster(fill = NA) geom_spatraster(aes(fill = NULL)). aes(fill = ggplot2::after_stat()) now works geom_spatraster(). Internal: Better handling aes() layers Add new function stat_spatraster(). Reduce size external files.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-022","dir":"Changelog","previous_headings":"","what":"tidyterra 0.2.2","title":"tidyterra 0.2.2","text":"CRAN release: 2022-09-29 Changes dplyr, tibble tidyr attached. Now packages listed ‘Depends’ attached tidyterra library require called. Messages load can suppressed suppressPackageStartupMessages(library(tidyterra)).","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-021","dir":"Changelog","previous_headings":"","what":"tidyterra 0.2.1","title":"tidyterra 0.2.1","text":"CRAN release: 2022-09-23 Now geom_spatraster_rgb() works facet_wrap() (#35) Improve faceting plot facets created using non-Spat* layers. Precompute vignettes.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-020","dir":"Changelog","previous_headings":"","what":"tidyterra 0.2.0","title":"tidyterra 0.2.0","text":"CRAN release: 2022-06-21 Recreate extdata/volcano2.tif using official DEM information New Zealand. Source: Auckland LiDAR 1m DEM (2013). Add volcano2 dataset. Fix errors slice_min() slice_max() SpatRaster objects (#20). Also add new parameter na.rm. scale_fill_hypso_c() scale_fill_whitebox_c() scale_fill_wiki_c() scale_fill_cross_blended_c() Add new asia.tif file extdata.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-010","dir":"Changelog","previous_headings":"","what":"tidyterra 0.1.0","title":"tidyterra 0.1.0","text":"CRAN release: 2022-05-24 Add DOI. CRAN release.","code":""},{"path":"https://dieghernan.github.io/tidyterra/news/index.html","id":"tidyterra-001","dir":"Changelog","previous_headings":"","what":"tidyterra 0.0.1","title":"tidyterra 0.0.1","text":"Conversion tibble avoided much possible. Internally use data.tables instead tibbles. package compatible dtplyr. as_spatraster() handles tibbles characters factors. Simplification tests geom_spatraster() geom_spatraster_rgb(). pull() transmute() rename() geom_spatraster_contour() family.","code":""}]