├── .Rbuildignore ├── .github ├── .gitignore ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── check-dplyr-readr.yaml │ ├── check-full.yaml │ ├── check-ggplot2-devel.yaml │ ├── check-sf-devel.yaml │ ├── check-terra-devel.yaml │ ├── cran-status-check.yaml │ ├── lintr.yaml │ ├── pkgcheck.yaml │ ├── pkgdown-gh-pages.yaml │ ├── recheck.yaml │ ├── revdepcheck.yaml │ ├── rhub.yaml │ ├── test-coverage.yaml │ ├── update-docs.yaml │ └── wipe-cache.yaml ├── .gitignore ├── .imgbotconfig ├── .lintr ├── CITATION.cff ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── arrange-SpatVector.R ├── as_coordinates.R ├── as_sf.R ├── as_spatraster.R ├── as_spatvector.R ├── as_tibble-Spat.R ├── autoplot-Spat.R ├── bind-cols-SpatVector.R ├── bind-rows-SpatVector.R ├── compare_spatrasters.R ├── count-tally-SpatVector.R ├── data.R ├── distinct-SpatVector.R ├── drop_na-Spat.R ├── fill-SpatVector.R ├── filter-Spat.R ├── fortify-Spat.R ├── geom_spat_contour.R ├── geom_spat_contour_fill.R ├── geom_spat_contour_text.R ├── geom_spatraster.R ├── geom_spatraster_rgb.R ├── geom_spatvector.R ├── glimpse-Spat.R ├── group-by-SpatVector.R ├── group-data-SpatVector.R ├── grouped-SpatVector.R ├── is_regular_grid.R ├── join-SpatVector.R ├── mutate-Spat.R ├── pivot-long-SpatVector.R ├── pivot-wide-SpatVector.R ├── pull-Spat.R ├── pull_crs.R ├── relocate-Spat.R ├── rename-Spat.R ├── replace_na-Spat.R ├── rowwise-SpatVector.R ├── scales_coltab.R ├── scales_cross_blended.R ├── scales_grass.R ├── scales_hypso.R ├── scales_princess.R ├── scales_terrain.R ├── scales_whitebox.R ├── scales_wiki.R ├── select-Spat.R ├── slice-Spat.R ├── stat_spat_coordinates.R ├── stat_spatraster.R ├── summarise-SpatVector.R ├── sysdata.rda ├── tidyterra-package.R ├── utils-pipe.R └── utils.R ├── README.Rmd ├── README.md ├── codemeta.json ├── data-raw ├── U2018_CLC2018_V2020_20u1.tif ├── asia.R ├── asia.tif ├── clc_edinburgh.R ├── clc_edinburgh.tif ├── clc_edinburgh.tif.aux.xml ├── cpt │ ├── DEM_poster.cpt │ ├── DEM_print.cpt │ ├── DEM_screen.cpt │ ├── ETOPO1.cpt │ ├── GMT_globe.cpt │ ├── arctic.Rds │ ├── arctic.cpt │ ├── artic.R │ ├── c3t1.R │ ├── c3t1.Rds │ ├── c3t1.cpt │ ├── colombia.R │ ├── colombia.Rds │ ├── colombia.cpt │ ├── dem-poster.R │ ├── dem-print.R │ ├── dem-screen.R │ ├── dem_poster.Rds │ ├── dem_print.Rds │ ├── dem_screen.Rds │ ├── etopo1.R │ ├── etopo1.Rds │ ├── gmt_globe.R │ ├── gmt_globe.Rds │ ├── meyers.R │ ├── meyers.Rds │ ├── meyers.cpt │ ├── moon.R │ ├── moon.Rds │ ├── moon.cpt │ ├── nordisk-familjebok.R │ ├── nordisk-familjebok.Rds │ ├── nordisk-familjebok.cpt │ ├── pakistan.R │ ├── pakistan.Rds │ ├── pakistan.cpt │ ├── spain.R │ ├── spain.Rds │ ├── spain.cpt │ ├── usgs-gswa2.R │ ├── usgs-gswa2.Rds │ ├── usgs-gswa2.cpt │ ├── utah_1.R │ ├── utah_1.Rds │ ├── utah_1.cpt │ ├── wiki-2.0.Rds │ ├── wiki-2.0.cpt │ ├── wiki-schwarzwald-cont.R │ ├── wiki-schwarzwald-cont.Rds │ ├── wiki-schwarzwald-cont.cpt │ └── wiki_2.0.R ├── cross_blended_hypsometric_tints_db.R ├── cyl-gpkg.R ├── cyl_era.R ├── dems │ └── .gitignore ├── grass │ ├── aspect.R │ ├── aspect.rds │ ├── aspectcolr.R │ ├── aspectcolr.rds │ ├── bcyr.R │ ├── bcyr.rds │ ├── bgyr.R │ ├── bgyr.rds │ ├── blues.R │ ├── blues.rds │ ├── byg.R │ ├── byg.rds │ ├── byr.R │ ├── byr.rds │ ├── celsius.R │ ├── celsius.rds │ ├── corine.R │ ├── corine.rds │ ├── curvature.R │ ├── curvature.rds │ ├── differences.R │ ├── differences.rds │ ├── elevation.R │ ├── elevation.rds │ ├── etopo2.R │ ├── etopo2.rds │ ├── evi.R │ ├── evi.rds │ ├── fahrenheit.R │ ├── fahrenheit.rds │ ├── forest_cover.R │ ├── forest_cover.rds │ ├── gdd.R │ ├── gdd.rds │ ├── grass.R │ ├── grass.rds │ ├── greens.R │ ├── greens.rds │ ├── grey.R │ ├── grey.rds │ ├── gyr.R │ ├── gyr.rds │ ├── haxby.R │ ├── haxby.rds │ ├── inferno.R │ ├── inferno.rds │ ├── kelvin.R │ ├── kelvin.rds │ ├── magma.R │ ├── magma.rds │ ├── ndvi.R │ ├── ndvi.rds │ ├── ndwi.R │ ├── ndwi.rds │ ├── nlcd.R │ ├── nlcd.rds │ ├── oranges.R │ ├── oranges.rds │ ├── plasma.R │ ├── plasma.rds │ ├── population.R │ ├── population.rds │ ├── population_dens.R │ ├── population_dens.rds │ ├── precipitation.R │ ├── precipitation.rds │ ├── precipitation_daily.R │ ├── precipitation_daily.rds │ ├── precipitation_monthly.R │ ├── precipitation_monthly.rds │ ├── rainbow.R │ ├── rainbow.rds │ ├── ramp.R │ ├── ramp.rds │ ├── reds.R │ ├── reds.rds │ ├── roygbiv.R │ ├── roygbiv.rds │ ├── rstcurv.R │ ├── rstcurv.rds │ ├── ryb.R │ ├── ryb.rds │ ├── ryg.R │ ├── ryg.rds │ ├── sepia.R │ ├── sepia.rds │ ├── slope.R │ ├── slope.rds │ ├── soilmoisture.R │ ├── soilmoisture.rds │ ├── srtm.R │ ├── srtm.rds │ ├── srtm_plus.R │ ├── srtm_plus.rds │ ├── terrain.R │ ├── terrain.rds │ ├── viridis.R │ ├── viridis.rds │ ├── water.R │ ├── water.rds │ ├── wave.R │ └── wave.rds ├── grass_db.R ├── holyroodpark.R ├── holyroodpark.tif ├── hypsometric_tints_db.R ├── princess_db.R ├── sysdata.R ├── test_corine.R ├── unitsdb.R ├── volcano2.R ├── volcano2.tif ├── volcano2_dataset.R ├── volcano2hires.tif ├── volcano_maungawhau.asc └── volcano_ok.R ├── data ├── cross_blended_hypsometric_tints_db.rda ├── grass_db.rda ├── hypsometric_tints_db.rda ├── princess_db.rda └── volcano2.rda ├── img ├── README-example-temp-1.png ├── README-example-temp-2.png ├── README-example-tile-1.png ├── README-example-tile-2.png ├── README-hypso-1.png ├── README-hypso-2.png ├── README-spatvec-1.png └── spatraster-example-1.png ├── inst ├── CITATION ├── WORDLIST ├── extdata │ ├── asia.tif │ ├── cyl.gpkg │ ├── cyl_elev.tif │ ├── cyl_era.tif │ ├── cyl_era.tif.aux.xml │ ├── cyl_temp.tif │ ├── cyl_tile.tif │ └── volcano2.tif └── schemaorg.json ├── man ├── arrange.SpatVector.Rd ├── as_coordinates.Rd ├── as_sf.Rd ├── as_spatraster.Rd ├── as_spatvector.Rd ├── as_tibble.Spat.Rd ├── autoplot.Spat.Rd ├── bind_cols.SpatVector.Rd ├── bind_rows.SpatVector.Rd ├── chunks │ └── grassdec.Rmd ├── compare_spatrasters.Rd ├── count.SpatVector.Rd ├── cross_blended_hypsometric_tints_db.Rd ├── distinct.SpatVector.Rd ├── drop_na.Spat.Rd ├── figures │ ├── lifecycle-archived.svg │ ├── lifecycle-defunct.svg │ ├── lifecycle-deprecated.svg │ ├── lifecycle-experimental.svg │ ├── lifecycle-maturing.svg │ ├── lifecycle-questioning.svg │ ├── lifecycle-stable.svg │ ├── lifecycle-superseded.svg │ └── logo.png ├── fill.SpatVector.Rd ├── filter-joins.SpatVector.Rd ├── filter.Spat.Rd ├── fortify.Spat.Rd ├── geom_spat_contour.Rd ├── geom_spatraster.Rd ├── geom_spatraster_rgb.Rd ├── ggspatvector.Rd ├── glimpse.Spat.Rd ├── grass_db.Rd ├── group-by.SpatVector.Rd ├── group_data.SpatVector.Rd ├── hypsometric_tints_db.Rd ├── is_grouped_spatvector.Rd ├── is_regular_grid.Rd ├── mutate-joins.SpatVector.Rd ├── mutate.Spat.Rd ├── pipe.Rd ├── pivot_longer.SpatVector.Rd ├── pivot_wider.SpatVector.Rd ├── princess_db.Rd ├── pull.Spat.Rd ├── pull_crs.Rd ├── reexports.Rd ├── relocate.Spat.Rd ├── rename.Spat.Rd ├── replace_na.Spat.Rd ├── rowwise.SpatVector.Rd ├── roxygen │ └── meta.R ├── scale_coltab.Rd ├── scale_cross_blended.Rd ├── scale_grass.Rd ├── scale_hypso.Rd ├── scale_princess.Rd ├── scale_terrain.Rd ├── scale_whitebox.Rd ├── scale_wiki.Rd ├── select.Spat.Rd ├── slice.Spat.Rd ├── stat_spat_coordinates.Rd ├── summarise.SpatVector.Rd ├── tidyterra-package.Rd └── volcano2.Rd ├── pkgdown ├── _pkgdown.yml └── favicon │ ├── apple-touch-icon.png │ ├── favicon-96x96.png │ ├── favicon.ico │ ├── favicon.svg │ ├── site.webmanifest │ ├── web-app-manifest-192x192.png │ └── web-app-manifest-512x512.png ├── revdep ├── .gitignore ├── README.md ├── cran.md ├── failures.md └── problems.md ├── tests ├── testthat.R └── testthat │ ├── _snaps │ ├── as_coordinates.md │ ├── as_sf.md │ ├── as_spatraster.md │ ├── as_spatvector.md │ ├── as_tibble-Spat.md │ ├── autoplot-Spat.md │ ├── autoplot-Spat │ │ ├── coltab-01-regular.svg │ │ ├── coltab-02-no-facets-forced.svg │ │ ├── coltab-03-no-facets-auto.svg │ │ ├── coltab-04-two-rows.svg │ │ ├── coltab-5-force-no-facets.svg │ │ ├── coltab-6-not-use-coltab.svg │ │ ├── norgb-01-regular.svg │ │ ├── norgb-02-categorical.svg │ │ ├── norgb-03-no-facets-auto.svg │ │ ├── norgb-03-no-facets-forced.svg │ │ ├── norgb-04-three-rows.svg │ │ ├── norgb-05-four-cols.svg │ │ ├── norgb-06-force-no-facets.svg │ │ ├── rgb-01-regular-forced.svg │ │ ├── rgb-01-regular.svg │ │ ├── rgb-02-with-opts.svg │ │ ├── rgb-03-change-coords.svg │ │ ├── rgb-04-facets-does-not-affect.svg │ │ ├── rgb-05-forced-to-non-rgb.svg │ │ ├── vector-01-regular.svg │ │ ├── vector-02-aes.svg │ │ └── vector-03-aes-inherited.svg │ ├── bind-cols-SpatVector.md │ ├── bind-rows-SpatVector.md │ ├── compare_spatrasters.md │ ├── count-tally-SpatVector.md │ ├── distinct-SpatVector.md │ ├── drop_na-Spat.md │ ├── fortify-Spat.md │ ├── geom_spat_contour.md │ ├── geom_spat_contour │ │ ├── 01-regular.svg │ │ ├── 02-projected.svg │ │ ├── 03-faceted-with-aes.svg │ │ ├── 04-faceted-with-aes-and-crs.svg │ │ ├── 05-aes-for-layer.svg │ │ ├── 06-aes-for-layer-aes-and-crs.svg │ │ ├── 07-wrap.svg │ │ ├── 08-no-wrap.svg │ │ ├── 09-no-wrap-facet.svg │ │ ├── crsfacet-01-regular.svg │ │ ├── crsfacet-02-color.svg │ │ └── crsfacet-03-change-crs.svg │ ├── geom_spat_contour_fill.md │ ├── geom_spat_contour_fill │ │ ├── 01-regular.svg │ │ ├── 02-projected.svg │ │ ├── 03-faceted-with-aes.svg │ │ ├── 04-faceted-with-aes-and-crs.svg │ │ ├── 05-aes-for-layer.svg │ │ ├── 06-aes-for-layer-aes-and-crs.svg │ │ ├── 07-align-binwd.svg │ │ ├── 08-align-binwd-trans.svg │ │ ├── 09-align-bins.svg │ │ ├── 10-align-bins-trans.svg │ │ ├── 11-align-breaks.svg │ │ ├── 12-align-breaks-trans.svg │ │ ├── 13-wrap.svg │ │ ├── 14-no-wrap.svg │ │ ├── 15-no-wrap-facet.svg │ │ ├── crsfacet-01-regular.svg │ │ ├── crsfacet-02-color.svg │ │ └── crsfacet-03-change-crs.svg │ ├── geom_spat_contour_text.md │ ├── geom_spat_contour_text │ │ ├── 01-regular.svg │ │ ├── 02-projected.svg │ │ ├── 03-faceted-with-aes.svg │ │ ├── 04-faceted-with-aes-and-crs.svg │ │ ├── 05-aes-for-layer.svg │ │ ├── 06-aes-for-layer-aes-and-crs.svg │ │ ├── 07-wrap.svg │ │ ├── 08-no-wrap.svg │ │ ├── 09-no-wrap-facet.svg │ │ ├── crsfacet-01-regular.svg │ │ ├── crsfacet-02-color.svg │ │ └── crsfacet-03-change-crs.svg │ ├── geom_spatraster_1lyr.md │ ├── geom_spatraster_1lyr │ │ ├── crs-01-regular.svg │ │ ├── crs-02-w-scale-cont.svg │ │ ├── crs-03-w-scale-breaks.svg │ │ ├── crs-04-w-facets.svg │ │ ├── crs-05-w-aes.svg │ │ ├── crs-06-categ-w-scale-disc.svg │ │ ├── crs-07-resampled.svg │ │ ├── crs-08-resampled-interpolated.svg │ │ ├── crs-09-change-crs.svg │ │ ├── crs-10-with-sf.svg │ │ ├── crs-11-with-crs-and-sf.svg │ │ ├── crs-12-with-sf-first.svg │ │ ├── crs-13-with-sf-first-and-crs.svg │ │ ├── crs-14-suppress-colors-and-overlay.svg │ │ ├── crs-14-suppress-colors.svg │ │ ├── crs-15-stat-works.svg │ │ ├── crs-16-wrap.svg │ │ ├── crs-17-no-wrap.svg │ │ ├── crsfacet-01-regular.svg │ │ ├── crsfacet-02-color.svg │ │ ├── crsfacet-03-change-crs.svg │ │ ├── nocrs-01a-regular.svg │ │ ├── nocrs-01b-regular-with-coord-equal.svg │ │ ├── nocrs-02-w-scale-cont.svg │ │ ├── nocrs-03-w-scale-breaks.svg │ │ ├── nocrs-04-w-facets.svg │ │ ├── nocrs-05-w-aes.svg │ │ ├── nocrs-06-categ-w-scale-disc.svg │ │ ├── nocrs-07-resampled.svg │ │ ├── nocrs-08-resampled-interpolated.svg │ │ ├── nocrs-09-change-crs.svg │ │ ├── nocrs-10-with-sf.svg │ │ ├── nocrs-11-with-crs-and-sf.svg │ │ ├── nocrs-12-with-sf-reprojected.svg │ │ ├── nocrs-14-suppress-colors-and-overlay.svg │ │ ├── nocrs-14-suppress-colors.svg │ │ └── nocrs-15-stat-works.svg │ ├── geom_spatraster_1lyr_coltab.md │ ├── geom_spatraster_1lyr_coltab │ │ ├── crs-01-regular.svg │ │ ├── crs-02-nocoltab.svg │ │ ├── crs-03-w-scale-disc.svg │ │ ├── crs-04-w-facets.svg │ │ ├── crs-05-w-aes.svg │ │ ├── crs-06-resampled.svg │ │ ├── crs-07-resampled-interpolated.svg │ │ ├── crs-08-change-crs.svg │ │ ├── crs-10-with-crs-and-sf.svg │ │ ├── crs-11-with-sf-first.svg │ │ ├── crs-12-with-sf-first-and-crs.svg │ │ ├── crs-13-suppress-colors-and-overlay.svg │ │ ├── crs-13-suppress-colors.svg │ │ ├── crs-9-with-sf.svg │ │ ├── crsfacet-01-regular.svg │ │ ├── crsfacet-02-color.svg │ │ ├── crsfacet-03-change-crs.svg │ │ ├── nocrs-01a-regular.svg │ │ ├── nocrs-01b-regular-with-coord-equal.svg │ │ ├── nocrs-02-ncoltab.svg │ │ ├── nocrs-03-w-scale-disc.svg │ │ ├── nocrs-04-w-facets.svg │ │ ├── nocrs-05-w-aes.svg │ │ ├── nocrs-07-resampled.svg │ │ ├── nocrs-08-resampled-interpolated.svg │ │ ├── nocrs-09-change-crs.svg │ │ ├── nocrs-10-with-sf.svg │ │ ├── nocrs-11-with-crs-and-sf.svg │ │ ├── nocrs-12-with-sf-reprojected.svg │ │ ├── nocrs-14-suppress-colors-and-overlay.svg │ │ └── nocrs-14-suppress-colors.svg │ ├── geom_spatraster_3lyr.md │ ├── geom_spatraster_3lyr │ │ ├── crs-01a-regular-no-facet.svg │ │ ├── crs-01b-regular-facet.svg │ │ ├── crs-02-w-scale-cont.svg │ │ ├── crs-03-w-scale-breaks.svg │ │ ├── crs-04-w-facets.svg │ │ ├── crs-05-w-aes.svg │ │ ├── crs-06a-categ-w-scale-disc.svg │ │ ├── crs-06b-mixed-with-nums.svg │ │ ├── crs-06c-mixed-with-chars.svg │ │ ├── crs-07-resampled.svg │ │ ├── crs-08-resampled-interpolated.svg │ │ ├── crs-09-change-crs.svg │ │ ├── crs-10-with-sf.svg │ │ ├── crs-11-with-crs-and-sf.svg │ │ ├── crs-12-with-sf-first.svg │ │ ├── crs-13-with-sf-first-and-crs.svg │ │ ├── crs-14-suppress-colors-and-overlay.svg │ │ ├── crs-14-suppress-colors.svg │ │ ├── crs-15-stat-works.svg │ │ ├── crs-16-combine-levels.svg │ │ ├── crs-17-wrap.svg │ │ ├── crs-18-no-wrap.svg │ │ ├── nocrs-01a-regular-no-facet.svg │ │ ├── nocrs-01b-regular-facet.svg │ │ ├── nocrs-01c-regular-facet-with-coords.svg │ │ ├── nocrs-02-w-scale-cont.svg │ │ ├── nocrs-03-w-scale-breaks.svg │ │ ├── nocrs-04-w-facets.svg │ │ ├── nocrs-05-w-aes.svg │ │ ├── nocrs-06a-categ-w-scale-disc.svg │ │ ├── nocrs-06b-mixed-with-nums.svg │ │ ├── nocrs-06c-mixed-with-chars.svg │ │ ├── nocrs-07-resampled.svg │ │ ├── nocrs-08-resampled-interpolated.svg │ │ ├── nocrs-09-change-crs.svg │ │ ├── nocrs-10-with-sf.svg │ │ ├── nocrs-11-with-crs-and-sf.svg │ │ ├── nocrs-12-with-sf-reprojected.svg │ │ ├── nocrs-14-suppress-colors-and-overlay.svg │ │ ├── nocrs-14-suppress-colors.svg │ │ └── nocrs-15-stat-works.svg │ ├── geom_spatraster_3lyr_coltab.md │ ├── geom_spatraster_3lyr_coltab │ │ ├── crs-01a-regular-no-facet.svg │ │ ├── crs-01b-regular-facet.svg │ │ ├── crs-02-w-aes.svg │ │ ├── crs-03-categ-w-scale-disc.svg │ │ ├── crs-04-mixed-with-nums.svg │ │ ├── crs-05-resampled.svg │ │ ├── crs-06-change-crs.svg │ │ ├── crs-07-mix-factors-coltab-first.svg │ │ └── crs-08-mix-factors-coltab-second.svg │ ├── geom_spatraster_rgb.md │ ├── geom_spatraster_rgb │ │ ├── crs-01-regular.svg │ │ ├── crs-02-change-channels.svg │ │ ├── crs-03-resampled.svg │ │ ├── crs-04-resampled-interpolated.svg │ │ ├── crs-05-change-crs.svg │ │ ├── crs-06-with-sf.svg │ │ ├── crs-07-with-sf-first.svg │ │ ├── crs-08-with-sf-first-and-crs.svg │ │ ├── crs-09-check-maxcol.svg │ │ ├── crs-10-no-wrap.svg │ │ ├── crs-11-wrap.svg │ │ ├── crsfacet-01-regular.svg │ │ ├── crsfacet-02-fill.svg │ │ ├── crsfacet-03-change-crs.svg │ │ ├── crsmask-01-regular.svg │ │ ├── crsmask-02-change-channels.svg │ │ ├── crsmask-03-resampled.svg │ │ ├── crsmask-04-resampled-interpolated.svg │ │ ├── crsmask-05-change-crs.svg │ │ ├── crsmask-06-with-sf.svg │ │ ├── crsmask-07-with-sf-first.svg │ │ ├── crsmask-08-with-sf-first-and-crs.svg │ │ ├── crsmask-09-check-maxcol.svg │ │ ├── crsstretch-01-regular.svg │ │ ├── crsstretch-02-zlim.svg │ │ ├── crsstretch-03-zlim-lin.svg │ │ ├── crsstretch-04-zlim-lin.svg │ │ ├── crsstretch-05-hist.svg │ │ ├── nocrs-01a-regular.svg │ │ ├── nocrs-01b-regular-flip.svg │ │ ├── nocrs-02-change-channels.svg │ │ ├── nocrs-03-resampled.svg │ │ ├── nocrs-04-resampled-interpolated.svg │ │ ├── nocrs-05-change-crs.svg │ │ ├── nocrs-06-with-sf.svg │ │ ├── nocrs-07-with-crs-and-sf.svg │ │ ├── nocrs-08-with-sf-reprojected.svg │ │ ├── nocrs-09-check-maxcol.svg │ │ ├── nocrsmask-01a-regular.svg │ │ ├── nocrsmask-01b-regular-flip.svg │ │ ├── nocrsmask-02-change-channels.svg │ │ ├── nocrsmask-03-resampled.svg │ │ ├── nocrsmask-04-resampled-interpolated.svg │ │ ├── nocrsmask-05-change-crs.svg │ │ ├── nocrsmask-06-with-sf.svg │ │ ├── nocrsmask-07-with-crs-and-sf.svg │ │ ├── nocrsmask-08-with-sf-reprojected.svg │ │ └── nocrsmask-09-check-maxcol.svg │ ├── glimpse-Spat.md │ ├── group-by-SpatVector-terra.md │ ├── join-SpatVector.md │ ├── keep_coltab │ │ ├── coltab-orig.svg │ │ ├── drop-na.svg │ │ ├── filter.svg │ │ ├── mutate1.svg │ │ ├── mutate2.svg │ │ ├── mutate3.svg │ │ ├── mutate4.svg │ │ ├── relocate.svg │ │ ├── rename.svg │ │ ├── replace-na.svg │ │ ├── select-several.svg │ │ ├── select-with-rename.svg │ │ ├── select1.svg │ │ ├── select2.svg │ │ ├── transmute1.svg │ │ ├── transmute2.svg │ │ ├── transmute3.svg │ │ └── transmute4.svg │ ├── mutate-Spat.md │ ├── pivot-long-SpatVector.md │ ├── pivot-wide-SpatVector.md │ ├── pull_crs.md │ ├── rowwise-SpatVector-terra.md │ ├── rowwise-SpatVector.md │ ├── scales_col_cross_blended.md │ ├── scales_col_cross_blended │ │ ├── pr165-01-nolims.svg │ │ ├── pr165-02-lims1.svg │ │ └── pr165-03-lims1.svg │ ├── scales_col_hypso.md │ ├── scales_col_terrain.md │ ├── scales_col_whitebox.md │ ├── scales_col_wiki.md │ ├── scales_coltab.md │ ├── scales_fill_cross_blended.md │ ├── scales_fill_hypso.md │ ├── scales_fill_hypso │ │ ├── pr165-01-nolims.svg │ │ ├── pr165-02-lims1.svg │ │ └── pr165-03-lims1.svg │ ├── scales_fill_terrain.md │ ├── scales_fill_whitebox.md │ ├── scales_fill_wiki.md │ ├── scales_grass.md │ ├── scales_grass │ │ ├── pr165-01-nolims.svg │ │ ├── pr165-02-lims1.svg │ │ └── pr165-03-lims1.svg │ ├── scales_princess.md │ ├── select-Spat.md │ ├── slice-SpatVector.md │ ├── stat_spatraster.md │ └── stat_spatraster │ │ ├── crslyr1-01-regular.svg │ │ ├── crslyr1-02-w-facets.svg │ │ ├── crslyr1-03-w-aes.svg │ │ ├── crslyr1-04-points.svg │ │ ├── crslyr1-05-text.svg │ │ ├── nocrslyr1-01-regular.svg │ │ ├── nocrslyr1-02-w-facets.svg │ │ ├── nocrslyr1-03-w-aes.svg │ │ ├── nocrslyr1-04-points.svg │ │ └── nocrslyr1-05-text.svg │ ├── test-arrange-SpatVector.R │ ├── test-as_coordinates.R │ ├── test-as_sf.R │ ├── test-as_spatraster.R │ ├── test-as_spatvector.R │ ├── test-as_tibble-Spat.R │ ├── test-autoplot-Spat.R │ ├── test-bind-cols-SpatVector.R │ ├── test-bind-rows-SpatVector.R │ ├── test-compare_spatrasters.R │ ├── test-count-tally-SpatVector.R │ ├── test-distinct-SpatVector.R │ ├── test-drop_na-Spat.R │ ├── test-fill-SpatVector.R │ ├── test-filter-Spat.R │ ├── test-fortify-Spat.R │ ├── test-geom_spat_contour.R │ ├── test-geom_spat_contour_fill.R │ ├── test-geom_spat_contour_text.R │ ├── test-geom_spatraster_1lyr.R │ ├── test-geom_spatraster_1lyr_coltab.R │ ├── test-geom_spatraster_3lyr.R │ ├── test-geom_spatraster_3lyr_coltab.R │ ├── test-geom_spatraster_rgb.R │ ├── test-geom_spatvector.R │ ├── test-glimpse-Spat.R │ ├── test-group-by-SpatVector-terra.R │ ├── test-group-by-SpatVector.R │ ├── test-group-data-SpatVector.R │ ├── test-join-SpatVector.R │ ├── test-keep_coltab.R │ ├── test-mutate-Spat.R │ ├── test-pivot-long-SpatVector.R │ ├── test-pivot-wide-SpatVector.R │ ├── test-pull-Spat.R │ ├── test-pull_crs.R │ ├── test-relocate-Spat.R │ ├── test-rename-Spat.R │ ├── test-replace_na-Spat.R │ ├── test-rowwise-SpatVector-terra.R │ ├── test-rowwise-SpatVector.R │ ├── test-scales_col_cross_blended.R │ ├── test-scales_col_hypso.R │ ├── test-scales_col_terrain.R │ ├── test-scales_col_whitebox.R │ ├── test-scales_col_wiki.R │ ├── test-scales_coltab.R │ ├── test-scales_fill_cross_blended.R │ ├── test-scales_fill_hypso.R │ ├── test-scales_fill_terrain.R │ ├── test-scales_fill_whitebox.R │ ├── test-scales_fill_wiki.R │ ├── test-scales_grass.R │ ├── test-scales_princess.R │ ├── test-select-Spat.R │ ├── test-slice-SpatRaster.R │ ├── test-slice-SpatVector.R │ ├── test-stat_spatraster.R │ ├── test-summarise-SpatVector.R │ ├── test-transmute-Spat.R │ └── test-utils.R ├── tidyterra.Rproj └── vignettes ├── .gitignore ├── aggregate-1.png ├── aggregate-2.png ├── articles ├── Esri.WorldShadedRelief │ ├── 83d8f6fd655e9e33554068e008a466ff.tif │ ├── 83d8f6fd655e9e33554068e008a466ff.tif.aux.xml │ ├── Esri.WorldShadedRelief_8_132_89.jpg │ ├── Esri.WorldShadedRelief_8_132_90.jpg │ ├── Esri.WorldShadedRelief_8_132_91.jpg │ ├── Esri.WorldShadedRelief_8_133_89.jpg │ ├── Esri.WorldShadedRelief_8_133_90.jpg │ ├── Esri.WorldShadedRelief_8_133_91.jpg │ ├── Esri.WorldShadedRelief_8_134_89.jpg │ ├── Esri.WorldShadedRelief_8_134_90.jpg │ ├── Esri.WorldShadedRelief_8_134_91.jpg │ ├── Esri.WorldShadedRelief_8_135_89.jpg │ ├── Esri.WorldShadedRelief_8_135_90.jpg │ └── Esri.WorldShadedRelief_8_135_91.jpg ├── INPUBS.bib ├── OpenStreetMap │ ├── 3ff88f2a659533f469cb56031b4fb4b2.tif │ ├── 3ff88f2a659533f469cb56031b4fb4b2.tif.aux.xml │ ├── 9f654eb084cc35bf3b45121bab5cc4ba.tif │ ├── 9f654eb084cc35bf3b45121bab5cc4ba.tif.aux.xml │ ├── OpenStreetMap_14_8047_5105.png │ ├── OpenStreetMap_14_8047_5106.png │ ├── OpenStreetMap_14_8048_5105.png │ └── OpenStreetMap_14_8048_5106.png ├── apa.csl ├── bk_INPUBS.bib ├── che_temp.gif ├── clc_edinburgh.tif ├── clc_edinburgh.tif.aux.xml ├── climate │ └── wc2.1_country │ │ ├── CHE_wc2.1_30s_prec.tif │ │ └── CHE_wc2.1_30s_tavg.tif ├── faqs.Rmd ├── gadm │ └── gadm41_CHE_0_pk.rds ├── holyroodpark.tif ├── palettes.Rmd └── wild.Rmd ├── contourfilled-1.png ├── contourlines-1.png ├── faceted-1.png ├── hypso-1.png ├── lux_ggplot-1.png ├── paper.bib ├── rgb-1.png ├── spatraster-example1-1.png ├── spatraster-example2-1.png ├── tidyterra.Rmd ├── tidyterra.Rmd.orig ├── welcome.Rmd └── welcome.Rmd.orig /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^tidyterra\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^data-raw$ 5 | ^dev$ 6 | ^revdep$ 7 | ^codemeta\.json$ 8 | ^CITATION\.cff$ 9 | ^CRAN-SUBMISSION$ 10 | ^docs$ 11 | ^pkgdown$ 12 | ^README\.Rmd$ 13 | ^tests/testthat/_snaps$ 14 | ^\.github$ 15 | ^tidyterra\.Rcheck$ 16 | ^tidyterra.*\.tar\.gz$ 17 | ^tidyterra.*\.tgz$ 18 | ^cran-comments\.md$ 19 | ^doc$ 20 | ^Meta$ 21 | ^img$ 22 | ^vignettes/articles$ 23 | ^vignettes/tidyterra\.Rmd\.orig$ 24 | ^\.imgbotconfig$ 25 | ^pkgdown\.yaml$ 26 | ^pkgdown\.yml$ 27 | ^CODE_OF_CONDUCT\.md$ 28 | ^CONTRIBUTING\.md$ 29 | ^\.lintr$ 30 | ^vignettes/welcome\.Rmd\.orig$ 31 | ^Rplots\.pdf$ 32 | ^codecov\.yml$ 33 | ^_pkgdown\.yaml$ 34 | ^_pkgdown\.yml$ 35 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | R-version 2 | depends.Rds 3 | *.html 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: dieghernan 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: dieghernan 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 12 | polar: # Replace with a single Polar username 13 | buy_me_a_coffee: # Replace with a single Buy Me a Coffee username 14 | thanks_dev: # Replace with a single thanks.dev username 15 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 16 | 17 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | # Basic set up for three package managers 7 | 8 | version: 2 9 | updates: 10 | 11 | # Maintain dependencies for GitHub Actions 12 | - package-ecosystem: "github-actions" 13 | directory: "/" 14 | schedule: 15 | interval: "weekly" 16 | 17 | -------------------------------------------------------------------------------- /.github/workflows/cran-status-check.yaml: -------------------------------------------------------------------------------- 1 | name: CRAN Status Monitor 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '0 10 * * 1,3,5' 7 | 8 | jobs: 9 | check: 10 | runs-on: ubuntu-latest 11 | permissions: write-all 12 | env: 13 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 14 | 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v4 18 | 19 | - name: Check 20 | uses: dieghernan/cran-status-check@v2 21 | with: 22 | fail-on-error: "true" 23 | create-issue: "false" 24 | 25 | -------------------------------------------------------------------------------- /.github/workflows/pkgcheck.yaml: -------------------------------------------------------------------------------- 1 | name: pkgcheck - rOpenSci 2 | 3 | # This will cancel running jobs once a new run is triggered 4 | concurrency: 5 | group: ${{ github.workflow }}-${{ github.head_ref }} 6 | cancel-in-progress: true 7 | 8 | on: 9 | # Manually trigger the Action under Actions/pkgcheck 10 | workflow_dispatch: 11 | 12 | jobs: 13 | pkgcheck: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: ropensci-review-tools/pkgcheck-action@main 17 | with: 18 | summary-only: false 19 | post-to-issue: true 20 | append-to-issue: true 21 | 22 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown-gh-pages.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/master/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [main, master] 7 | tags: ['*'] 8 | 9 | name: pkgdown-gh-pages 10 | 11 | jobs: 12 | pkgdown-gh-pages: 13 | runs-on: windows-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | CURL_SSL_BACKEND: "openssl" 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - uses: r-lib/actions/setup-pandoc@v2 21 | 22 | - uses: r-lib/actions/setup-r@v2 23 | with: 24 | use-public-rspm: true 25 | install-r: true 26 | 27 | - uses: r-lib/actions/setup-r-dependencies@v2 28 | with: 29 | cache-version: pkgdown 30 | extra-packages: | 31 | local::. 32 | any::pkgdown 33 | needs: website 34 | 35 | - name: Deploy package 36 | run: | 37 | git config --local user.name "github-actions[bot]" 38 | git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" 39 | Rscript -e 'pkgdown::deploy_to_branch(clean = TRUE)' 40 | 41 | -------------------------------------------------------------------------------- /.github/workflows/recheck.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-devel/recheck 2 | on: 3 | workflow_dispatch: 4 | inputs: 5 | which: 6 | type: choice 7 | description: Which dependents to check 8 | options: 9 | - strong 10 | - most 11 | 12 | name: r-devel reverse dependency check 13 | 14 | jobs: 15 | revdep_check: 16 | name: Reverse check ${{ inputs.which }} dependents 17 | uses: r-devel/recheck/.github/workflows/recheck.yml@v1 18 | with: 19 | which: ${{ inputs.which }} 20 | 21 | -------------------------------------------------------------------------------- /.github/workflows/update-docs.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_dispatch: 3 | 4 | name: Update docs 5 | 6 | jobs: 7 | update-docs: 8 | runs-on: windows-latest 9 | env: 10 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 11 | CURL_SSL_BACKEND: "openssl" 12 | steps: 13 | - uses: actions/checkout@v4 14 | 15 | - uses: r-lib/actions/setup-pandoc@v2 16 | 17 | - uses: r-lib/actions/setup-r@v2 18 | with: 19 | use-public-rspm: true 20 | install-r: true 21 | 22 | 23 | - uses: r-lib/actions/setup-r-dependencies@v2 24 | with: 25 | cache-version: pkgdown 26 | extra-packages: | 27 | local::. 28 | any::cli 29 | any::rcmdcheck 30 | any::pkgdown 31 | dieghernan/pkgdev 32 | 33 | needs: website 34 | 35 | - name: Update docs 36 | run: | 37 | 38 | pkgdev::precompute_vignette_all() 39 | pkgdev::update_docs(precompute = FALSE, add_contributors = FALSE) 40 | 41 | shell: Rscript {0} 42 | 43 | - name: Commit results 44 | run: | 45 | git config --local user.name "github-actions[bot]" 46 | git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" 47 | git add -A 48 | git commit -m 'Update docs with pkgdev' || echo "No changes to commit" 49 | git push origin || echo "No changes to commit" 50 | 51 | - uses: r-lib/actions/check-r-package@v2 52 | 53 | - name: Deploy package 54 | run: | 55 | git config --local user.name "github-actions[bot]" 56 | git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" 57 | Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, run_dont_run = TRUE)' 58 | 59 | -------------------------------------------------------------------------------- /.github/workflows/wipe-cache.yaml: -------------------------------------------------------------------------------- 1 | name: Clear GHA caches 2 | on: 3 | workflow_dispatch: 4 | schedule: 5 | - cron: '30 10 * * 2,5' 6 | jobs: 7 | cache-clear: 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: easimon/wipe-cache@main 12 | 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .Rapp.history 4 | .RData 5 | .Ruserdata 6 | *-Ex.R 7 | /*.tar.gz 8 | /*.Rcheck/ 9 | .Rproj.user/ 10 | vignettes/*.html 11 | vignettes/*.pdf 12 | .httr-oauth 13 | *_cache/ 14 | /cache/ 15 | *.utf8.md 16 | *.knit.md 17 | .Renviron 18 | docs 19 | dev 20 | tidyterra.Rcheck/ 21 | tidyterra*.tar.gz 22 | tidyterra*.tgz 23 | CRAN-SUBMISSION 24 | .github/pkg.lock 25 | inst/doc 26 | cran-comments.md 27 | /doc/ 28 | /Meta/ 29 | .Rdata 30 | Rplots.pdf 31 | -------------------------------------------------------------------------------- /.imgbotconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignoredFiles": [ 3 | "/tests/testthat/_snaps/*", 4 | "/man/figures/lifecycle*" 5 | ], 6 | "compressWiki": "true", 7 | "aggressiveCompression": "true" 8 | } 9 | -------------------------------------------------------------------------------- /.lintr: -------------------------------------------------------------------------------- 1 | linters: linters_with_defaults() # see vignette("lintr") 2 | encoding: "UTF-8" 3 | exclusions: list("data-raw") 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2022 2 | COPYRIGHT HOLDER: tidyterra authors 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2022 tidyterra authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /R/grouped-SpatVector.R: -------------------------------------------------------------------------------- 1 | #' A grouped `SpatVector` 2 | #' 3 | #' @description 4 | #' The easiest way to create a grouped `SpatVector` is to call the 5 | #' `group_by()` method on a `SpatVector`: this will take care of capturing 6 | #' the unevaluated expressions for you. See [group_by.SpatVector()] for details. 7 | #' 8 | #' This function is the adapted version of [dplyr::is_grouped_df()]. 9 | #' 10 | #' See also [group_data.SpatVector()] for the accessory functions that retrieve 11 | #' various metadata from a grouped `SpatVector`. 12 | #' 13 | #' @keywords internal 14 | #' @param x a `SpatVector`. 15 | #' 16 | #' 17 | #' @family helpers 18 | #' 19 | #' @export 20 | is_grouped_spatvector <- function(x) { 21 | att <- attributes(x) 22 | 23 | if (all(att$tblclass == "grouped_df", inherits(att$groups, "tbl_df"))) { 24 | return(TRUE) 25 | } 26 | 27 | return(FALSE) 28 | } 29 | -------------------------------------------------------------------------------- /R/stat_spat_coordinates.R: -------------------------------------------------------------------------------- 1 | #' Extract coordinates from `SpatVector` objects 2 | #' 3 | #' `stat_spat_coordinates()` extracts the coordinates from `SpatVector` objects 4 | #' and summarises them to one pair of coordinates (x and y) per geometry. 5 | #' 6 | #' Wrapper of [ggplot2::stat_sf_coordinates()]. 7 | #' 8 | #' 9 | #' @rdname stat_spat_coordinates 10 | #' 11 | #' @export 12 | #' @family ggplot2.utils 13 | #' @return A \CRANpkg{ggplot2} layer 14 | #' @keywords internal 15 | #' 16 | #' 17 | #' @inheritParams ggspatvector 18 | #' @inheritParams ggplot2::stat_sf_coordinates 19 | #' @param ... Other arguments passed on to [ggplot2::stat_sf_coordinates()]. 20 | #' 21 | #' @details 22 | #' 23 | #' See [ggplot2::stat_sf_coordinates()] for details. 24 | #' 25 | #' 26 | #' @examples 27 | #' \donttest{ 28 | #' cyl <- terra::vect(system.file("extdata/cyl.gpkg", package = "tidyterra")) 29 | #' 30 | #' library(ggplot2) 31 | #' 32 | #' ggplot(cyl) + 33 | #' stat_spat_coordinates() 34 | #' 35 | #' ggplot(cyl) + 36 | #' geom_errorbarh( 37 | #' aes( 38 | #' geometry = geometry, 39 | #' xmin = after_stat(x) - 50000, 40 | #' xmax = after_stat(x) + 50000, 41 | #' y = after_stat(y), 42 | #' height = 10000 43 | #' ), 44 | #' stat = "sf_coordinates" 45 | #' ) 46 | #' } 47 | #' 48 | stat_spat_coordinates <- function(mapping = aes(), data = NULL, geom = "point", 49 | position = "identity", na.rm = FALSE, 50 | show.legend = NA, inherit.aes = TRUE, 51 | ...) { 52 | # nocov start 53 | ggplot2::stat_sf_coordinates( 54 | mapping = mapping, data = data, geom = geom, 55 | position = position, na.rm = na.rm, 56 | show.legend = show.legend, inherit.aes = inherit.aes, 57 | ... 58 | ) 59 | # nocov end 60 | } 61 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/R/sysdata.rda -------------------------------------------------------------------------------- /R/tidyterra-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | "_PACKAGE" 3 | 4 | #' @importFrom ggplot2 aes after_stat 5 | #' @importFrom rlang .data 6 | #' @importFrom grDevices terrain.colors rgb col2rgb grey 7 | #' @importFrom tibble as_tibble 8 | #' @importFrom cli qty 9 | #' @importFrom utils packageVersion 10 | NULL 11 | 12 | #' @export 13 | ggplot2::aes 14 | 15 | #' @export 16 | ggplot2::after_stat 17 | -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | #' @param lhs A value or the magrittr placeholder. 12 | #' @param rhs A function call using the magrittr semantics. 13 | #' @return The result of calling `rhs(lhs)`. 14 | NULL 15 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | across_all_of <- function(vars) { 2 | dplyr::across(dplyr::all_of(vars)) 3 | } 4 | 5 | as_spat_internal <- function(x) { 6 | if (any( 7 | inherits(x, "SpatRaster"), 8 | isTRUE(attr(x, "source") == "SpatRaster") 9 | )) { 10 | return(as_spatrast_attr(x)) 11 | } else if (any( 12 | inherits(x, "SpatVector"), 13 | isTRUE(attr(x, "source") == "SpatVector") 14 | )) { 15 | return(as_spatvect_attr(x)) 16 | } 17 | 18 | 19 | cli::cli_abort(paste( 20 | "Can't convert {.arg x} back to a {.cls Spat*} object.", 21 | "Something went wrong" 22 | )) 23 | } 24 | 25 | # Restore attributes from template 26 | restore_attr <- function(x, template) { 27 | init_attr <- attributes(x) 28 | temp_attr <- attributes(template) 29 | 30 | addatt <- setdiff(names(temp_attr), names(init_attr)) 31 | 32 | finalattr <- c(init_attr, temp_attr[addatt]) 33 | 34 | attributes(x) <- finalattr 35 | 36 | x 37 | } 38 | 39 | #' Create safe index name 40 | #' @param x pattern to create 41 | #' @param y object with names (Can perform `names(y)`) to assess. 42 | #' @noRd 43 | make_safe_index <- function(x, y) { 44 | nams <- names(y) 45 | 46 | i <- 1 47 | 48 | init_x <- x 49 | 50 | is_safe <- !(x %in% nams) 51 | 52 | while (isFALSE(is_safe)) { 53 | x <- paste0(init_x, "_", sprintf("%03d", i)) 54 | i <- i + 1 55 | is_safe <- !(x %in% nams) 56 | } 57 | 58 | return(x) 59 | } 60 | -------------------------------------------------------------------------------- /data-raw/U2018_CLC2018_V2020_20u1.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/U2018_CLC2018_V2020_20u1.tif -------------------------------------------------------------------------------- /data-raw/asia.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `asia.tif` dataset goes here 2 | 3 | 4 | asiaraw <- terra::rast("data-raw/asia.tif") 5 | template <- terra::project(asiaraw, "EPSG:3857") 6 | terra::ncell(template) 7 | template <- terra::spatSample(template, 50000, 8 | method = "regular", 9 | as.raster = TRUE 10 | ) 11 | terra::ncell(template) 12 | asia <- terra::project(asiaraw, template, method = "cubic") 13 | asiaraw 14 | asia 15 | 16 | terra::plot(asia) 17 | 18 | devtools::load_all() 19 | library(ggplot2) 20 | 21 | ggplot() + 22 | geom_spatraster(data = asia) + 23 | scale_fill_hypso_tint_c( 24 | palette = "gmt_globe", 25 | labels = scales::label_number(), 26 | breaks = c(-10000, -5000, 0, 2500, 5000, 8000), 27 | guide = guide_colorbar() 28 | ) + 29 | labs( 30 | fill = "elevation (m)", 31 | title = "Hypsometric map of Asia" 32 | ) + 33 | theme_minimal() 34 | unlink("inst/extdata/asia.tif") 35 | terra::writeRaster(asia, "inst/extdata/asia.tif") 36 | -------------------------------------------------------------------------------- /data-raw/asia.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/asia.tif -------------------------------------------------------------------------------- /data-raw/clc_edinburgh.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/clc_edinburgh.tif -------------------------------------------------------------------------------- /data-raw/cpt/DEM_poster.cpt: -------------------------------------------------------------------------------- 1 | # cpt file created by: Thomas Dewez for elevations 2 | #COLOR_MODEL = RGB 3 | # 4 | 0 0 97 71 50 16 122 47 5 | 50 16 122 47 500 232 215 125 6 | 500 232 215 125 1200 161 67 0 7 | 1200 161 67 0 1700 158 0 0 8 | 1700 158 0 0 2800 110 110 110 9 | 2800 110 110 110 4000 255 255 255 10 | 4000 255 255 255 4900 255 255 255 11 | N 153 204 255 12 | F 153 204 255 13 | B 153 204 255 14 | -------------------------------------------------------------------------------- /data-raw/cpt/DEM_print.cpt: -------------------------------------------------------------------------------- 1 | # cpt file created by: Thomas Dewez for printing 2 | # 3 | # COLOR_MODEL = RGB 4 | 0 51 102 0 100 129 195 31 5 | 100 129 195 31 200 255 255 204 6 | 200 255 255 204 400 244 189 69 7 | 400 244 189 69 500 102 51 12 8 | 500 102 51 12 600 102 51 0 9 | 600 102 51 0 800 255 255 255 10 | B 51 102 0 11 | F 255 255 255 12 | N 51 102 0 13 | -------------------------------------------------------------------------------- /data-raw/cpt/DEM_screen.cpt: -------------------------------------------------------------------------------- 1 | # cpt file created by: Thomas Dewez for elevations 2 | # 3 | # COLOR_MODEL = RGB 4 | 0 0 132 53 100 51 204 0 5 | 100 51 204 0 200 244 240 113 6 | 200 244 240 113 400 244 189 69 7 | 400 244 189 69 600 153 100 43 8 | 600 153 100 43 800 255 255 255 9 | B 255 255 255 10 | F 0 132 53 11 | N 0 132 53 12 | -------------------------------------------------------------------------------- /data-raw/cpt/arctic.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/arctic.Rds -------------------------------------------------------------------------------- /data-raw/cpt/c3t1.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/c3t1.Rds -------------------------------------------------------------------------------- /data-raw/cpt/c3t1.cpt: -------------------------------------------------------------------------------- 1 | # c3t1.cpt 2 | # autogenerated GMT palette "c3t1.dat" 3 | # cptutils version 1.31, Sat Jun 13 00:32:11 2009 4 | # COLOR_MODEL = RGB 5 | 0.000000e+00 137 185 148 2.000000e+01 137 185 148 6 | 2.000000e+01 159 200 167 5.000000e+01 159 200 167 7 | 5.000000e+01 190 221 188 1.000000e+02 190 221 188 8 | 1.000000e+02 229 230 201 2.000000e+02 229 230 201 9 | 2.000000e+02 255 252 200 3.000000e+02 255 252 200 10 | 3.000000e+02 255 241 198 5.000000e+02 255 241 198 11 | 5.000000e+02 255 232 181 7.500000e+02 255 232 181 12 | 7.500000e+02 255 221 162 1.000000e+03 255 221 162 13 | 1.000000e+03 255 211 144 1.500000e+03 255 211 144 14 | B 0 0 0 15 | F 254 204 128 16 | N 255 0 0 17 | -------------------------------------------------------------------------------- /data-raw/cpt/colombia.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/colombia.Rds -------------------------------------------------------------------------------- /data-raw/cpt/colombia.cpt: -------------------------------------------------------------------------------- 1 | # colombia.cpt 2 | # GMT colour palette by Shadowxfox 3 | # http://fr.wikipedia.org/wiki/Fichier:Colombia_Mapa_Relieve.svg 4 | # licence: http://creativecommons.org/licenses/by-sa/3.0/deed.fr 5 | # COLOR_MODEL = RGB 6 | -4000 0 30 80 -3000 0 30 80 7 | -3000 0 51 102 -2000 0 51 102 8 | -2000 0 102 153 -1000 0 102 153 9 | -1000 0 153 205 -500 0 153 205 10 | -500 100 200 255 -200 100 200 255 11 | -200 198 236 255 0 198 236 255 12 | 0 148 171 132 100 148 171 132 13 | 100 172 191 139 200 172 191 139 14 | 200 189 204 150 500 189 204 150 15 | 500 228 223 175 1000 228 223 175 16 | 1000 230 202 148 2000 230 202 148 17 | 2000 205 171 131 3000 205 171 131 18 | 3000 181 152 128 4000 181 152 128 19 | 4000 155 123 98 5000 155 123 98 20 | -------------------------------------------------------------------------------- /data-raw/cpt/dem_poster.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/dem_poster.Rds -------------------------------------------------------------------------------- /data-raw/cpt/dem_print.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/dem_print.Rds -------------------------------------------------------------------------------- /data-raw/cpt/dem_screen.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/dem_screen.Rds -------------------------------------------------------------------------------- /data-raw/cpt/etopo1.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/etopo1.Rds -------------------------------------------------------------------------------- /data-raw/cpt/gmt_globe.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/gmt_globe.Rds -------------------------------------------------------------------------------- /data-raw/cpt/meyers.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/meyers.Rds -------------------------------------------------------------------------------- /data-raw/cpt/meyers.cpt: -------------------------------------------------------------------------------- 1 | # An elevation scheme extracted from scan of map from 2 | # Meyers Konversationslexikon (1885–90) 3 | # http://commons.wikimedia.org/wiki/File:Meyers_b1_s0457a.jpg 4 | # 5 | # Public domain (due to age of document) 6 | # 7 | # Extraction by J.J. Green 2012 8 | # $Id: meyers.cpt,v 1.1 2012/04/02 21:04:17 jjg Exp $ 9 | # 10 | # COLOR_MODEL = RGB 11 | -6000 91 140 164 -4000 91 140 164 12 | -4000 120 164 183 -2000 120 164 183 13 | -2000 128 173 193 -1000 128 173 193 14 | -1000 146 182 195 -200 146 182 195 15 | -200 200 219 225 0 200 219 225 16 | 0 178 202 153 200 178 202 153 17 | 200 215 224 199 500 215 224 199 18 | 500 208 195 180 1000 208 195 180 19 | 1000 155 115 93 2000 155 115 93 20 | 2000 100 53 32 3000 100 53 32 21 | 3000 43 10 11 4000 43 10 11 22 | B 91 140 164 23 | F 43 10 11 24 | N 255 0 0 25 | -------------------------------------------------------------------------------- /data-raw/cpt/moon.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/moon.Rds -------------------------------------------------------------------------------- /data-raw/cpt/nordisk-familjebok.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/nordisk-familjebok.Rds -------------------------------------------------------------------------------- /data-raw/cpt/nordisk-familjebok.cpt: -------------------------------------------------------------------------------- 1 | # An elevation scheme extracted from scan "Nordisk 2 | # familjebok Nord-Amerika. Flod- och bergssystem" 3 | # http://runeberg.org/nfba/0430.html 4 | # 5 | # Public domain (due to age of document) 6 | # 7 | # Extraction by J.J. Green 2012 8 | # $Id: nordisk-familjebok.cpt,v 1.1 2012/04/02 21:04:17 jjg Exp $ 9 | # 10 | # COLOR_MODEL = RGB 11 | -8000 108 139 141 -6000 108 139 141 12 | -6000 129 159 144 -4000 129 159 144 13 | -4000 169 182 162 -2000 169 182 162 14 | -2000 192 198 173 -200 192 198 173 15 | -200 230 221 204 0 230 221 204 16 | 0 188 187 128 200 188 187 128 17 | 200 207 199 153 500 207 199 153 18 | 500 227 194 165 1000 227 194 165 19 | 1000 215 158 120 2000 215 158 120 20 | 2000 213 130 85 3000 213 130 85 21 | 3000 93 42 19 4000 93 42 19 22 | B 108 139 141 23 | F 93 42 19 24 | N 255 0 0 -------------------------------------------------------------------------------- /data-raw/cpt/pakistan.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/pakistan.Rds -------------------------------------------------------------------------------- /data-raw/cpt/pakistan.cpt: -------------------------------------------------------------------------------- 1 | # afganistan.cpt 2 | # author: http://commons.wikimedia.org/wiki/User:Jarke 3 | # source: http://fr.wikipedia.org/wiki/Fichier:Pakistan_geography_en.svg 4 | # licence: http://creativecommons.org/licenses/by-sa/3.0/deed.fr 5 | # COLOR_MODEL = RGB 6 | 0 218 228 201 200 218 228 201 7 | 200 233 234 194 400 233 234 194 8 | 400 240 236 209 1000 240 236 209 9 | 1000 242 227 189 1500 242 227 189 10 | 1500 237 207 162 2000 237 207 162 11 | 2000 226 197 150 3000 226 197 150 12 | 3000 202 186 224 4000 202 186 224 13 | 4000 223 214 236 6000 223 214 236 14 | 6000 243 243 255 8611 243 243 255 15 | -------------------------------------------------------------------------------- /data-raw/cpt/spain.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/spain.Rds -------------------------------------------------------------------------------- /data-raw/cpt/usgs-gswa2.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/usgs-gswa2.Rds -------------------------------------------------------------------------------- /data-raw/cpt/usgs-gswa2.cpt: -------------------------------------------------------------------------------- 1 | # COLOR_MODEL = RGB 2 | 0.000 127 159 101 0.048 130 174 106 3 | 0.048 130 174 106 0.095 160 194 122 4 | 0.095 160 194 122 0.143 186 214 140 5 | 0.143 186 214 140 0.190 207 226 156 6 | 0.190 207 226 156 0.238 224 233 166 7 | 0.238 224 233 166 0.286 237 236 166 8 | 0.286 237 236 166 0.333 242 228 159 9 | 0.333 242 228 159 0.381 240 210 144 10 | 0.381 240 210 144 0.429 230 188 136 11 | 0.429 230 188 136 0.476 216 165 133 12 | 0.476 216 165 133 0.524 197 149 138 13 | 0.524 197 149 138 0.571 217 165 146 14 | 0.571 217 165 146 0.619 227 181 153 15 | 0.619 227 181 153 0.667 233 196 160 16 | 0.667 233 196 160 0.714 234 208 170 17 | 0.714 234 208 170 0.762 230 214 182 18 | 0.762 230 214 182 0.810 228 218 194 19 | 0.810 228 218 194 0.857 230 219 206 20 | 0.857 230 219 206 0.905 240 220 220 21 | 0.905 240 220 220 0.952 250 230 237 22 | 0.952 250 230 237 1.000 255 255 255 23 | F 255 255 255 24 | -------------------------------------------------------------------------------- /data-raw/cpt/utah_1.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/utah_1.Rds -------------------------------------------------------------------------------- /data-raw/cpt/wiki-2.0.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/wiki-2.0.Rds -------------------------------------------------------------------------------- /data-raw/cpt/wiki-schwarzwald-cont.Rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/cpt/wiki-schwarzwald-cont.Rds -------------------------------------------------------------------------------- /data-raw/dems/.gitignore: -------------------------------------------------------------------------------- 1 | NT27SE_50CM_DSM_PHASE5.tif 2 | -------------------------------------------------------------------------------- /data-raw/grass/aspect.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "aspect" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | lapply(strsplit, split = ":") 23 | 24 | pal_df <- lapply(tratapal, function(f) { 25 | tb <- as.double(unlist(f)[-1]) 26 | names(tb) <- c("r", "g", "b") 27 | df <- as.data.frame(t(tb)) 28 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 29 | df$pal <- pal 30 | 31 | df 32 | }) %>% 33 | bind_rows() %>% 34 | select(pal, r, g, b, hex) 35 | 36 | # Try 37 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 38 | 39 | library(ggplot2) 40 | library(tidyterra) 41 | ggplot() + 42 | geom_spatraster(data = r) + 43 | scale_fill_gradientn( 44 | colours = pal_df$hex, 45 | na.value = "lightblue" 46 | ) 47 | 48 | 49 | 50 | 51 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 52 | saveRDS(pal_df, extfile) 53 | -------------------------------------------------------------------------------- /data-raw/grass/aspect.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/aspect.rds -------------------------------------------------------------------------------- /data-raw/grass/aspectcolr.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "aspectcolr" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | tb2 <- col2rgb(tb[2]) %>% as.double() 25 | tb <- as.double(c(tb[1], tb2)) 26 | 27 | names(tb) <- c("limit", "r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, limit, r, g, b, hex) 36 | 37 | pal_df <- pal_df %>% 38 | group_by(limit) %>% 39 | slice_head(n = 1) %>% 40 | arrange(limit) 41 | 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | values = scales::rescale(pal_df$limit), 53 | limit = range(pal_df$limit), 54 | na.value = "lightblue" 55 | ) 56 | 57 | 58 | 59 | 60 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 61 | saveRDS(pal_df, extfile) 62 | -------------------------------------------------------------------------------- /data-raw/grass/aspectcolr.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/aspectcolr.rds -------------------------------------------------------------------------------- /data-raw/grass/bcyr.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "bcyr" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | tb2 <- col2rgb(tb[2]) %>% as.double() 25 | tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/bcyr.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/bcyr.rds -------------------------------------------------------------------------------- /data-raw/grass/bgyr.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "bgyr" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | tb2 <- col2rgb(tb[2]) %>% as.double() 25 | tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/bgyr.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/bgyr.rds -------------------------------------------------------------------------------- /data-raw/grass/blues.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "blues" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | tb2 <- col2rgb(tb[2]) %>% as.double() 25 | tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/blues.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/blues.rds -------------------------------------------------------------------------------- /data-raw/grass/byg.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "byg" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | tb2 <- col2rgb(tb[2]) %>% as.double() 25 | tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/byg.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/byg.rds -------------------------------------------------------------------------------- /data-raw/grass/byr.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "byr" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | tb2 <- col2rgb(tb[2]) %>% as.double() 25 | tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/byr.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/byr.rds -------------------------------------------------------------------------------- /data-raw/grass/celsius.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "celsius" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | head(init, 10) 11 | 12 | 13 | tratapal <- init[-c(1:7)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | names(tb) <- c("limit", "r", "g", "b") 25 | df <- as.data.frame(t(tb)) 26 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 27 | df$pal <- pal 28 | 29 | df 30 | }) %>% 31 | bind_rows() %>% 32 | select(pal, limit, r, g, b, hex) 33 | 34 | pal_df <- pal_df %>% 35 | group_by(limit) %>% 36 | slice_head(n = 1) 37 | 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | values = scales::rescale(pal_df$limit), 49 | limit = range(pal_df$limit), 50 | na.value = "lightblue" 51 | ) 52 | 53 | 54 | 55 | 56 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 57 | saveRDS(pal_df, extfile) 58 | -------------------------------------------------------------------------------- /data-raw/grass/celsius.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/celsius.rds -------------------------------------------------------------------------------- /data-raw/grass/corine.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "corine" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | names(tb) <- c("limit", "r", "g", "b") 25 | df <- as.data.frame(t(tb)) 26 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 27 | df$pal <- pal 28 | 29 | df 30 | }) %>% 31 | bind_rows() %>% 32 | select(pal, limit, r, g, b, hex) 33 | 34 | pal_df <- pal_df %>% 35 | group_by(limit) %>% 36 | slice_head(n = 1) 37 | 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | values = scales::rescale(pal_df$limit), 49 | limit = range(pal_df$limit), 50 | na.value = "lightblue" 51 | ) 52 | 53 | 54 | 55 | 56 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 57 | saveRDS(pal_df, extfile) 58 | -------------------------------------------------------------------------------- /data-raw/grass/corine.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/corine.rds -------------------------------------------------------------------------------- /data-raw/grass/curvature.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/curvature.rds -------------------------------------------------------------------------------- /data-raw/grass/differences.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "differences" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | tb2 <- col2rgb(tb[2]) %>% as.double() 25 | tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/differences.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/differences.rds -------------------------------------------------------------------------------- /data-raw/grass/elevation.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "elevation" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | tb2 <- as.double(tb[-1]) 25 | tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 57 | saveRDS(pal_df, extfile) 58 | -------------------------------------------------------------------------------- /data-raw/grass/elevation.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/elevation.rds -------------------------------------------------------------------------------- /data-raw/grass/etopo2.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "etopo2" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[-c(16)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | names(tb) <- c("limit", "r", "g", "b") 25 | df <- as.data.frame(t(tb)) 26 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 27 | df$pal <- pal 28 | 29 | df 30 | }) %>% 31 | bind_rows() %>% 32 | select(pal, limit, r, g, b, hex) 33 | 34 | pal_df <- pal_df %>% 35 | group_by(limit) %>% 36 | slice_head(n = 1) 37 | 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | values = scales::rescale(pal_df$limit), 49 | limit = range(pal_df$limit), 50 | na.value = "lightblue" 51 | ) 52 | 53 | 54 | 55 | 56 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 57 | saveRDS(pal_df, extfile) 58 | -------------------------------------------------------------------------------- /data-raw/grass/etopo2.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/etopo2.rds -------------------------------------------------------------------------------- /data-raw/grass/evi.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "evi" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", " ", .) %>% 19 | gsub(" ", " ", .) %>% 20 | gsub(" ", " ", .) %>% 21 | gsub(" ", ":", .) %>% 22 | gsub("aqua", paste0((col2rgb("#00FFFF")), collapse = ":"), .) %>% 23 | lapply(strsplit, split = ":") 24 | 25 | pal_df <- lapply(tratapal, function(f) { 26 | tb <- as.double(unlist(f)) 27 | tb <- tb[!is.na(tb)] 28 | names(tb) <- c("limit", "r", "g", "b") 29 | df <- as.data.frame(t(tb)) 30 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 31 | df$pal <- pal 32 | 33 | df 34 | }) %>% 35 | bind_rows() %>% 36 | select(pal, limit, r, g, b, hex) 37 | 38 | # Try 39 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 40 | endcols <- tidyterra:::tidyterra_ramp2(pal_df$hex, n = 10, limits = pal_df$limit) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = endcols, 48 | # values = scales::rescale(pal_df$limit), 49 | # limit = range(as.vector(terra::minmax(r))), 50 | na.value = "lightblue" 51 | ) 52 | hypso.colors2 53 | 54 | 55 | 56 | scales::show_col(endcols, labels = FALSE, ncol = 10) 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/evi.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/evi.rds -------------------------------------------------------------------------------- /data-raw/grass/fahrenheit.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "fahrenheit" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | head(init, n = 10) 11 | 12 | 13 | tratapal <- init[-c(1:7)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | names(tb) <- c("limit", "r", "g", "b") 25 | df <- as.data.frame(t(tb)) 26 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 27 | df$pal <- pal 28 | 29 | df 30 | }) %>% 31 | bind_rows() %>% 32 | select(pal, limit, r, g, b, hex) 33 | 34 | pal_df <- pal_df %>% 35 | group_by(limit) %>% 36 | slice_head(n = 1) 37 | 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | values = scales::rescale(pal_df$limit), 49 | limit = as.vector(terra::minmax(r)), 50 | na.value = "lightblue" 51 | ) 52 | 53 | 54 | 55 | 56 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 57 | saveRDS(pal_df, extfile) 58 | -------------------------------------------------------------------------------- /data-raw/grass/fahrenheit.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/fahrenheit.rds -------------------------------------------------------------------------------- /data-raw/grass/forest_cover.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "forest_cover" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[-c(1:2)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | names(tb) <- c("limit", "r", "g", "b") 25 | df <- as.data.frame(t(tb)) 26 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 27 | df$pal <- pal 28 | 29 | df 30 | }) %>% 31 | bind_rows() %>% 32 | select(pal, limit, r, g, b, hex) 33 | 34 | pal_df <- pal_df %>% 35 | group_by(limit) %>% 36 | slice_head(n = 1) %>% 37 | mutate(limit = limit / 100) 38 | 39 | 40 | # Try 41 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 42 | 43 | library(ggplot2) 44 | library(tidyterra) 45 | ggplot() + 46 | geom_spatraster(data = r) + 47 | scale_fill_gradientn( 48 | colours = pal_df$hex, 49 | values = scales::rescale(pal_df$limit), 50 | limit = as.vector(terra::minmax(r)), 51 | na.value = "lightblue" 52 | ) 53 | 54 | 55 | 56 | 57 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 58 | saveRDS(pal_df, extfile) 59 | -------------------------------------------------------------------------------- /data-raw/grass/forest_cover.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/forest_cover.rds -------------------------------------------------------------------------------- /data-raw/grass/gdd.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "gdd" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | 14 | tratapal <- init[] %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", " ", .) %>% 19 | gsub(" ", ":", .) %>% 20 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 21 | lapply(strsplit, split = ":") 22 | 23 | pal_df <- lapply(tratapal, function(f) { 24 | tb <- unlist(f) 25 | if (length(tb) == 2) { 26 | tb <- as.double(c(tb[1], col2rgb(tb[2]))) 27 | } else { 28 | tb <- as.double(tb) 29 | } 30 | 31 | names(tb) <- c("limit", "r", "g", "b") 32 | df <- as.data.frame(t(tb)) 33 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 34 | df$pal <- pal 35 | 36 | df 37 | }) %>% 38 | bind_rows() %>% 39 | select(pal, limit, r, g, b, hex) 40 | 41 | pal_df <- pal_df %>% 42 | group_by(limit) %>% 43 | slice_head(n = 1) 44 | 45 | as_tibble(pal_df) 46 | # Try 47 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 48 | 49 | library(ggplot2) 50 | library(tidyterra) 51 | ggplot() + 52 | geom_spatraster(data = r) + 53 | scale_fill_gradientn( 54 | colours = pal_df$hex, 55 | values = scales::rescale(pal_df$limit), 56 | limit = as.vector(terra::minmax(r)), 57 | na.value = "lightblue" 58 | ) 59 | 60 | 61 | 62 | 63 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 64 | saveRDS(pal_df, extfile) 65 | -------------------------------------------------------------------------------- /data-raw/grass/gdd.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/gdd.rds -------------------------------------------------------------------------------- /data-raw/grass/grass.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "grass" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | head(init, n = 10) 11 | 12 | 13 | tratapal <- init[-c(1:7)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | lapply(strsplit, split = ":") 23 | 24 | pal_df <- lapply(tratapal, function(f) { 25 | tb <- as.double(unlist(f)[-1]) 26 | names(tb) <- c("r", "g", "b") 27 | df <- as.data.frame(t(tb)) 28 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 29 | df$pal <- pal 30 | 31 | df 32 | }) %>% 33 | bind_rows() %>% 34 | select(pal, r, g, b, hex) 35 | 36 | # Try 37 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 38 | 39 | library(ggplot2) 40 | library(tidyterra) 41 | ggplot() + 42 | geom_spatraster(data = r) + 43 | scale_fill_gradientn( 44 | colours = pal_df$hex, 45 | na.value = "lightblue" 46 | ) 47 | 48 | 49 | 50 | 51 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 52 | saveRDS(pal_df, extfile) 53 | -------------------------------------------------------------------------------- /data-raw/grass/grass.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/grass.rds -------------------------------------------------------------------------------- /data-raw/grass/greens.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "greens" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | lapply(strsplit, split = ":") 24 | 25 | pal_df <- lapply(tratapal, function(f) { 26 | tb <- unlist(f)[-1] %>% as.double() 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # Try 38 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 39 | 40 | library(ggplot2) 41 | library(tidyterra) 42 | ggplot() + 43 | geom_spatraster(data = r) + 44 | scale_fill_gradientn( 45 | colours = pal_df$hex, 46 | na.value = "lightblue" 47 | ) 48 | 49 | 50 | as_tibble_col(pal_df) 51 | 52 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 53 | saveRDS(pal_df, extfile) 54 | -------------------------------------------------------------------------------- /data-raw/grass/greens.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/greens.rds -------------------------------------------------------------------------------- /data-raw/grass/grey.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "grey" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | lapply(strsplit, split = ":") 24 | 25 | pal_df <- lapply(tratapal, function(f) { 26 | tb <- unlist(f)[-1] %>% as.double() 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # Try 38 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 39 | 40 | library(ggplot2) 41 | library(tidyterra) 42 | ggplot() + 43 | geom_spatraster(data = r) + 44 | scale_fill_gradientn( 45 | colours = pal_df$hex, 46 | na.value = "lightblue" 47 | ) 48 | 49 | 50 | 51 | 52 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 53 | saveRDS(pal_df, extfile) 54 | -------------------------------------------------------------------------------- /data-raw/grass/grey.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/grey.rds -------------------------------------------------------------------------------- /data-raw/grass/gyr.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "gyr" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | gsub("yellow", paste0((col2rgb("yellow")), collapse = ":"), .) %>% 24 | gsub("red", paste0((col2rgb("red")), collapse = ":"), .) %>% 25 | lapply(strsplit, split = ":") 26 | 27 | pal_df <- lapply(tratapal, function(f) { 28 | tb <- unlist(f)[-1] %>% as.double() 29 | names(tb) <- c("r", "g", "b") 30 | df <- as.data.frame(t(tb)) 31 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 32 | df$pal <- pal 33 | 34 | df 35 | }) %>% 36 | bind_rows() %>% 37 | select(pal, r, g, b, hex) 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | na.value = "lightblue" 49 | ) 50 | 51 | 52 | 53 | 54 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 55 | saveRDS(pal_df, extfile) 56 | -------------------------------------------------------------------------------- /data-raw/grass/gyr.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/gyr.rds -------------------------------------------------------------------------------- /data-raw/grass/haxby.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "haxby" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | gsub("yellow", paste0((col2rgb("yellow")), collapse = ":"), .) %>% 24 | gsub("red", paste0((col2rgb("red")), collapse = ":"), .) %>% 25 | lapply(strsplit, split = ":") 26 | 27 | pal_df <- lapply(tratapal, function(f) { 28 | tb <- unlist(f)[-1] %>% as.double() 29 | names(tb) <- c("r", "g", "b") 30 | df <- as.data.frame(t(tb)) 31 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 32 | df$pal <- pal 33 | 34 | df 35 | }) %>% 36 | bind_rows() %>% 37 | select(pal, r, g, b, hex) 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | na.value = "lightblue" 49 | ) 50 | 51 | 52 | 53 | 54 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 55 | saveRDS(pal_df, extfile) 56 | -------------------------------------------------------------------------------- /data-raw/grass/haxby.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/haxby.rds -------------------------------------------------------------------------------- /data-raw/grass/inferno.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "inferno" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[-c(1:6)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | gsub("yellow", paste0((col2rgb("yellow")), collapse = ":"), .) %>% 24 | gsub("red", paste0((col2rgb("red")), collapse = ":"), .) %>% 25 | lapply(strsplit, split = ":") 26 | 27 | pal_df <- lapply(tratapal, function(f) { 28 | tb <- unlist(f)[-1] %>% as.double() 29 | names(tb) <- c("r", "g", "b") 30 | df <- as.data.frame(t(tb)) 31 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 32 | df$pal <- pal 33 | 34 | df 35 | }) %>% 36 | bind_rows() %>% 37 | select(pal, r, g, b, hex) 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | na.value = "lightblue" 49 | ) 50 | 51 | 52 | 53 | 54 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 55 | saveRDS(pal_df, extfile) 56 | -------------------------------------------------------------------------------- /data-raw/grass/inferno.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/inferno.rds -------------------------------------------------------------------------------- /data-raw/grass/kelvin.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "kelvin" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[-c(1:8)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | names(tb) <- c("limit", "r", "g", "b") 25 | df <- as.data.frame(t(tb)) 26 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 27 | df$pal <- pal 28 | 29 | df 30 | }) %>% 31 | bind_rows() %>% 32 | select(pal, limit, r, g, b, hex) 33 | 34 | pal_df <- pal_df %>% 35 | group_by(limit) %>% 36 | slice_head(n = 1) 37 | 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | values = scales::rescale(pal_df$limit), 49 | limit = as.vector(terra::minmax(r)), 50 | na.value = "lightblue" 51 | ) 52 | 53 | 54 | 55 | 56 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 57 | saveRDS(pal_df, extfile) 58 | -------------------------------------------------------------------------------- /data-raw/grass/kelvin.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/kelvin.rds -------------------------------------------------------------------------------- /data-raw/grass/magma.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "magma" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[-c(1:6)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | gsub("yellow", paste0((col2rgb("yellow")), collapse = ":"), .) %>% 24 | gsub("red", paste0((col2rgb("red")), collapse = ":"), .) %>% 25 | lapply(strsplit, split = ":") 26 | 27 | pal_df <- lapply(tratapal, function(f) { 28 | tb <- unlist(f)[-1] %>% as.double() 29 | names(tb) <- c("r", "g", "b") 30 | df <- as.data.frame(t(tb)) 31 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 32 | df$pal <- pal 33 | 34 | df 35 | }) %>% 36 | bind_rows() %>% 37 | select(pal, r, g, b, hex) 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | na.value = "lightblue" 49 | ) 50 | 51 | 52 | 53 | 54 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 55 | saveRDS(pal_df, extfile) 56 | -------------------------------------------------------------------------------- /data-raw/grass/magma.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/magma.rds -------------------------------------------------------------------------------- /data-raw/grass/ndvi.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "ndvi" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | tb <- tb[!is.na(tb)] 25 | names(tb) <- c("limit", "r", "g", "b") 26 | df <- as.data.frame(t(tb)) 27 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 28 | df$pal <- pal 29 | 30 | df 31 | }) %>% 32 | bind_rows() %>% 33 | select(pal, limit, r, g, b, hex) 34 | 35 | pal_df <- pal_df %>% 36 | group_by(limit) %>% 37 | slice_head(n = 1) 38 | 39 | 40 | # Try 41 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 42 | 43 | library(ggplot2) 44 | library(tidyterra) 45 | ggplot() + 46 | geom_spatraster(data = r) + 47 | scale_fill_gradientn( 48 | colours = pal_df$hex, 49 | values = scales::rescale(pal_df$limit), 50 | limit = as.vector(terra::minmax(r)), 51 | na.value = "lightblue" 52 | ) 53 | 54 | 55 | 56 | 57 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 58 | saveRDS(pal_df, extfile) 59 | -------------------------------------------------------------------------------- /data-raw/grass/ndvi.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/ndvi.rds -------------------------------------------------------------------------------- /data-raw/grass/ndwi.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "ndwi" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- (unlist(f)) 24 | tb <- tb[tb != ""] 25 | if (length(tb) == 2) { 26 | tb <- as.double(c(tb[1], col2rgb(tb[2]))) 27 | } else { 28 | tb <- as.double(tb) 29 | } 30 | 31 | names(tb) <- c("limit", "r", "g", "b") 32 | df <- as.data.frame(t(tb)) 33 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 34 | df$pal <- pal 35 | 36 | df 37 | }) %>% 38 | bind_rows() %>% 39 | select(pal, limit, r, g, b, hex) 40 | 41 | pal_df <- pal_df %>% 42 | group_by(limit) %>% 43 | slice_head(n = 1) %>% 44 | filter(abs(limit) < 2) %>% 45 | mutate(limit = limit * 200) 46 | 47 | 48 | # Try 49 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 50 | 51 | library(ggplot2) 52 | library(tidyterra) 53 | ggplot() + 54 | geom_spatraster(data = r) + 55 | scale_fill_gradientn( 56 | colours = pal_df$hex, 57 | values = scales::rescale(pal_df$limit), 58 | limit = as.vector(terra::minmax(r)), 59 | na.value = "lightblue" 60 | ) 61 | 62 | dev.off() 63 | scales::show_col(pal_df$hex) 64 | 65 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 66 | saveRDS(pal_df, extfile) 67 | -------------------------------------------------------------------------------- /data-raw/grass/ndwi.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/ndwi.rds -------------------------------------------------------------------------------- /data-raw/grass/nlcd.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "nlcd" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[-1] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | tb <- tb[!is.na(tb)] 25 | names(tb) <- c("limit", "r", "g", "b") 26 | df <- as.data.frame(t(tb)) 27 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 28 | df$pal <- pal 29 | 30 | df 31 | }) %>% 32 | bind_rows() %>% 33 | select(pal, limit, r, g, b, hex) 34 | 35 | pal_df <- pal_df %>% 36 | group_by(limit) %>% 37 | slice_head(n = 1) 38 | 39 | 40 | # Try 41 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 42 | 43 | library(ggplot2) 44 | library(tidyterra) 45 | ggplot() + 46 | geom_spatraster(data = r) + 47 | scale_fill_gradientn( 48 | colours = pal_df$hex, 49 | values = scales::rescale(pal_df$limit), 50 | limit = as.vector(terra::minmax(r)), 51 | na.value = "lightblue" 52 | ) 53 | 54 | 55 | 56 | 57 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 58 | saveRDS(pal_df, extfile) 59 | -------------------------------------------------------------------------------- /data-raw/grass/nlcd.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/nlcd.rds -------------------------------------------------------------------------------- /data-raw/grass/oranges.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "oranges" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | gsub("orange", paste0((col2rgb("orange")), collapse = ":"), .) %>% 24 | lapply(strsplit, split = ":") 25 | 26 | pal_df <- lapply(tratapal, function(f) { 27 | tb <- unlist(f)[-1] %>% as.double() 28 | names(tb) <- c("r", "g", "b") 29 | df <- as.data.frame(t(tb)) 30 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 31 | df$pal <- pal 32 | 33 | df 34 | }) %>% 35 | bind_rows() %>% 36 | select(pal, r, g, b, hex) 37 | 38 | # Try 39 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 40 | 41 | library(ggplot2) 42 | library(tidyterra) 43 | ggplot() + 44 | geom_spatraster(data = r) + 45 | scale_fill_gradientn( 46 | colours = pal_df$hex, 47 | na.value = "lightblue" 48 | ) 49 | 50 | 51 | as_tibble_col(pal_df) 52 | 53 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 54 | saveRDS(pal_df, extfile) 55 | -------------------------------------------------------------------------------- /data-raw/grass/oranges.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/oranges.rds -------------------------------------------------------------------------------- /data-raw/grass/plasma.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "plasma" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[-c(1:6)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | gsub("yellow", paste0((col2rgb("yellow")), collapse = ":"), .) %>% 24 | gsub("red", paste0((col2rgb("red")), collapse = ":"), .) %>% 25 | lapply(strsplit, split = ":") 26 | 27 | pal_df <- lapply(tratapal, function(f) { 28 | tb <- unlist(f)[-1] %>% as.double() 29 | names(tb) <- c("r", "g", "b") 30 | df <- as.data.frame(t(tb)) 31 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 32 | df$pal <- pal 33 | 34 | df 35 | }) %>% 36 | bind_rows() %>% 37 | select(pal, r, g, b, hex) 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | na.value = "lightblue" 49 | ) 50 | 51 | 52 | 53 | 54 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 55 | saveRDS(pal_df, extfile) 56 | -------------------------------------------------------------------------------- /data-raw/grass/plasma.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/plasma.rds -------------------------------------------------------------------------------- /data-raw/grass/population.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "population" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | tb <- tb[!is.na(tb)] 25 | names(tb) <- c("limit", "r", "g", "b") 26 | df <- as.data.frame(t(tb)) 27 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 28 | df$pal <- pal 29 | 30 | df 31 | }) %>% 32 | bind_rows() %>% 33 | select(pal, limit, r, g, b, hex) 34 | 35 | pal_df <- pal_df %>% 36 | group_by(limit) %>% 37 | slice_head(n = 1) %>% 38 | filter(limit < 10000000) 39 | 40 | 41 | # Try 42 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 43 | 44 | library(ggplot2) 45 | library(tidyterra) 46 | ggplot() + 47 | geom_spatraster(data = r) + 48 | scale_fill_gradientn( 49 | colours = pal_df$hex, 50 | # values = scales::rescale(pal_df$limit), 51 | # limit = as.vector(terra::minmax(r)), 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/population.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/population.rds -------------------------------------------------------------------------------- /data-raw/grass/population_dens.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "population_dens" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | tb <- tb[!is.na(tb)] 25 | names(tb) <- c("limit", "r", "g", "b") 26 | df <- as.data.frame(t(tb)) 27 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 28 | df$pal <- pal 29 | 30 | df 31 | }) %>% 32 | bind_rows() %>% 33 | select(pal, limit, r, g, b, hex) 34 | 35 | pal_df <- pal_df %>% 36 | group_by(limit) %>% 37 | slice_head(n = 1) %>% 38 | mutate(limit = pmin(limit, 1000)) %>% 39 | distinct() 40 | 41 | 42 | # Try 43 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 44 | 45 | library(ggplot2) 46 | library(tidyterra) 47 | ggplot() + 48 | geom_spatraster(data = r) + 49 | scale_fill_gradientn( 50 | colours = pal_df$hex, 51 | values = scales::rescale(pal_df$limit), 52 | limit = as.vector(terra::minmax(r)), 53 | na.value = "lightblue" 54 | ) 55 | 56 | 57 | 58 | 59 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 60 | saveRDS(pal_df, extfile) 61 | -------------------------------------------------------------------------------- /data-raw/grass/population_dens.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/population_dens.rds -------------------------------------------------------------------------------- /data-raw/grass/precipitation.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "precipitation" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | if (length(tb) == 2) { 25 | tb <- as.double(c(tb[1], col2rgb(tb[2]))) 26 | } 27 | tb <- as.double(tb) 28 | names(tb) <- c("limit", "r", "g", "b") 29 | df <- as.data.frame(t(tb)) 30 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 31 | df$pal <- pal 32 | 33 | df 34 | }) %>% 35 | bind_rows() %>% 36 | select(pal, limit, r, g, b, hex) 37 | 38 | pal_df <- pal_df %>% 39 | group_by(limit) %>% 40 | slice_head(n = 1) 41 | 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | values = scales::rescale(pal_df$limit), 53 | limit = as.vector(terra::minmax(r)), 54 | na.value = "lightblue" 55 | ) 56 | 57 | 58 | 59 | 60 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 61 | saveRDS(pal_df, extfile) 62 | -------------------------------------------------------------------------------- /data-raw/grass/precipitation.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/precipitation.rds -------------------------------------------------------------------------------- /data-raw/grass/precipitation_daily.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "precipitation_daily" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | if (length(tb) == 2) { 25 | tb <- as.double(c(tb[1], col2rgb(tb[2]))) 26 | } 27 | tb <- as.double(tb) 28 | names(tb) <- c("limit", "r", "g", "b") 29 | df <- as.data.frame(t(tb)) 30 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 31 | df$pal <- pal 32 | 33 | df 34 | }) %>% 35 | bind_rows() %>% 36 | select(pal, limit, r, g, b, hex) 37 | 38 | pal_df <- pal_df %>% 39 | group_by(limit) %>% 40 | slice_head(n = 1) %>% 41 | filter(limit < 200) 42 | 43 | 44 | # Try 45 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 46 | 47 | library(ggplot2) 48 | library(tidyterra) 49 | ggplot() + 50 | geom_spatraster(data = r) + 51 | scale_fill_gradientn( 52 | colours = pal_df$hex, 53 | # values = scales::rescale(pal_df$limit), 54 | # limit = as.vector(terra::minmax(r)), 55 | na.value = "lightblue" 56 | ) 57 | 58 | 59 | 60 | 61 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 62 | saveRDS(pal_df, extfile) 63 | -------------------------------------------------------------------------------- /data-raw/grass/precipitation_daily.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/precipitation_daily.rds -------------------------------------------------------------------------------- /data-raw/grass/precipitation_monthly.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "precipitation_monthly" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | head(init, n = 10) 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", "#00FFFF", .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | if (length(tb) == 2) { 25 | tb <- as.double(c(tb[1], col2rgb(tb[2]))) 26 | } 27 | tb <- as.double(tb) 28 | names(tb) <- c("limit", "r", "g", "b") 29 | df <- as.data.frame(t(tb)) 30 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 31 | df$pal <- pal 32 | 33 | df 34 | }) %>% 35 | bind_rows() %>% 36 | select(pal, limit, r, g, b, hex) 37 | 38 | pal_df <- pal_df %>% 39 | group_by(limit) %>% 40 | slice_head(n = 1) 41 | 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | # values = scales::rescale(pal_df$limit), 53 | # limit = as.vector(terra::minmax(r)), 54 | na.value = "lightblue" 55 | ) 56 | 57 | 58 | 59 | 60 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 61 | saveRDS(pal_df, extfile) 62 | -------------------------------------------------------------------------------- /data-raw/grass/precipitation_monthly.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/precipitation_monthly.rds -------------------------------------------------------------------------------- /data-raw/grass/rainbow.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "rainbow" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | # gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | # gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | # gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | # gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | lapply(strsplit, split = ":") 24 | 25 | pal_df <- lapply(tratapal, function(f) { 26 | tb <- unlist(f)[-1] %>% 27 | col2rgb() %>% 28 | as.double() 29 | names(tb) <- c("r", "g", "b") 30 | df <- as.data.frame(t(tb)) 31 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 32 | df$pal <- pal 33 | 34 | df 35 | }) %>% 36 | bind_rows() %>% 37 | select(pal, r, g, b, hex) 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | na.value = "lightblue" 49 | ) 50 | 51 | 52 | as_tibble_col(pal_df) 53 | 54 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 55 | saveRDS(pal_df, extfile) 56 | -------------------------------------------------------------------------------- /data-raw/grass/rainbow.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/rainbow.rds -------------------------------------------------------------------------------- /data-raw/grass/ramp.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "ramp" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | # gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | # gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | # gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | # gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | lapply(strsplit, split = ":") 24 | 25 | pal_df <- lapply(tratapal, function(f) { 26 | tb <- unlist(f)[-1] %>% 27 | col2rgb() %>% 28 | as.double() 29 | names(tb) <- c("r", "g", "b") 30 | df <- as.data.frame(t(tb)) 31 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 32 | df$pal <- pal 33 | 34 | df 35 | }) %>% 36 | bind_rows() %>% 37 | select(pal, r, g, b, hex) 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | na.value = "lightblue" 49 | ) 50 | 51 | 52 | as_tibble_col(pal_df) 53 | 54 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 55 | saveRDS(pal_df, extfile) 56 | -------------------------------------------------------------------------------- /data-raw/grass/ramp.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/ramp.rds -------------------------------------------------------------------------------- /data-raw/grass/reds.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "reds" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | # gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | # gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | # gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | # gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | lapply(strsplit, split = ":") 24 | 25 | pal_df <- lapply(tratapal, function(f) { 26 | tb <- unlist(f)[-1] %>% 27 | col2rgb() %>% 28 | as.double() 29 | names(tb) <- c("r", "g", "b") 30 | df <- as.data.frame(t(tb)) 31 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 32 | df$pal <- pal 33 | 34 | df 35 | }) %>% 36 | bind_rows() %>% 37 | select(pal, r, g, b, hex) 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | na.value = "lightblue" 49 | ) 50 | 51 | 52 | as_tibble_col(pal_df) 53 | 54 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 55 | saveRDS(pal_df, extfile) 56 | -------------------------------------------------------------------------------- /data-raw/grass/reds.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/reds.rds -------------------------------------------------------------------------------- /data-raw/grass/roygbiv.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "roygbiv" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[-1] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | # gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | # gsub("white", paste0((col2rgb("white")), collapse = ":"), .) %>% 21 | # gsub("black", paste0((col2rgb("black")), collapse = ":"), .) %>% 22 | # gsub("green", paste0((col2rgb("green")), collapse = ":"), .) %>% 23 | lapply(strsplit, split = ":") 24 | 25 | pal_df <- lapply(tratapal, function(f) { 26 | tb <- unlist(f)[-1] %>% as.double() 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # Try 38 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 39 | 40 | library(ggplot2) 41 | library(tidyterra) 42 | ggplot() + 43 | geom_spatraster(data = r) + 44 | scale_fill_gradientn( 45 | colours = pal_df$hex, 46 | na.value = "lightblue" 47 | ) 48 | 49 | 50 | as_tibble_col(pal_df) 51 | 52 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 53 | saveRDS(pal_df, extfile) 54 | -------------------------------------------------------------------------------- /data-raw/grass/roygbiv.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/roygbiv.rds -------------------------------------------------------------------------------- /data-raw/grass/rstcurv.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/rstcurv.rds -------------------------------------------------------------------------------- /data-raw/grass/ryb.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "ryb" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | tb2 <- col2rgb(tb[2]) %>% as.double() 25 | tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/ryb.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/ryb.rds -------------------------------------------------------------------------------- /data-raw/grass/ryg.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "ryg" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- unlist(f) 24 | tb2 <- col2rgb(tb[2]) %>% as.double() 25 | tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/ryg.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/ryg.rds -------------------------------------------------------------------------------- /data-raw/grass/sepia.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "sepia" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)[-1]) 24 | # tb2 <- col2rgb(tb[2]) %>% as.double() 25 | # tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/sepia.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/sepia.rds -------------------------------------------------------------------------------- /data-raw/grass/slope.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "slope" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | tratapal <- init[] %>% 13 | gsub(" ", ":", .) %>% 14 | lapply(strsplit, split = ":") 15 | 16 | pal_df <- lapply(tratapal, function(f) { 17 | tb <- as.double(unlist(f)) 18 | tb <- tb[!is.na(tb)] 19 | 20 | names(tb) <- c("limit", "r", "g", "b") 21 | df <- as.data.frame(t(tb)) 22 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 23 | df$pal <- pal 24 | 25 | df 26 | }) %>% 27 | bind_rows() %>% 28 | select(pal, limit, r, g, b, hex) 29 | 30 | pal_df 31 | 32 | scales::show_col(pal_df$hex) 33 | ncols <- 128 34 | col_end <- tidyterra:::tidyterra_ramp2(pal_df$hex, n = ncols, limits = pal_df$limit) 35 | 36 | image( 37 | x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), 38 | col = col_end, main = "test", 39 | ylab = "", xaxt = "n", yaxt = "n", bty = "n" 40 | ) 41 | 42 | # Try 43 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 44 | 45 | library(ggplot2) 46 | library(tidyterra) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | values = scales::rescale(pal_df$limit), 53 | limit = as.vector(terra::minmax(r)), 54 | na.value = "lightblue" 55 | ) 56 | 57 | 58 | as_tibble_col(pal_df) 59 | 60 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 61 | saveRDS(pal_df, extfile) 62 | -------------------------------------------------------------------------------- /data-raw/grass/slope.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/slope.rds -------------------------------------------------------------------------------- /data-raw/grass/soilmoisture.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "soilmoisture" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | tratapal <- init[] %>% 13 | gsub(" ", ":", .) %>% 14 | lapply(strsplit, split = ":") 15 | 16 | pal_df <- lapply(tratapal, function(f) { 17 | tb <- as.double(unlist(f)) 18 | tb <- tb[!is.na(tb)] 19 | 20 | names(tb) <- c("limit", "r", "g", "b") 21 | df <- as.data.frame(t(tb)) 22 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 23 | df$pal <- pal 24 | 25 | df 26 | }) %>% 27 | bind_rows() %>% 28 | select(pal, limit, r, g, b, hex) 29 | 30 | pal_df 31 | 32 | scales::show_col(pal_df$hex) 33 | ncols <- 128 34 | col_end <- tidyterra:::tidyterra_ramp2(pal_df$hex, n = ncols, limits = pal_df$limit) 35 | 36 | image( 37 | x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)), 38 | col = col_end, main = "test", 39 | ylab = "", xaxt = "n", yaxt = "n", bty = "n" 40 | ) 41 | 42 | # Try 43 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 44 | 45 | library(ggplot2) 46 | library(tidyterra) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | values = scales::rescale(pal_df$limit), 53 | limit = as.vector(terra::minmax(r)), 54 | na.value = "lightblue" 55 | ) 56 | 57 | 58 | as_tibble_col(pal_df) 59 | 60 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 61 | saveRDS(pal_df, extfile) 62 | -------------------------------------------------------------------------------- /data-raw/grass/soilmoisture.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/soilmoisture.rds -------------------------------------------------------------------------------- /data-raw/grass/srtm.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "srtm" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[-c(17)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("#00FFFF")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | names(tb) <- c("limit", "r", "g", "b") 25 | df <- as.data.frame(t(tb)) 26 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 27 | df$pal <- pal 28 | 29 | df 30 | }) %>% 31 | bind_rows() %>% 32 | select(pal, limit, r, g, b, hex) 33 | 34 | # Try 35 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 36 | 37 | library(ggplot2) 38 | library(tidyterra) 39 | ggplot() + 40 | geom_spatraster(data = r) + 41 | scale_fill_gradientn( 42 | colours = pal_df$hex, 43 | values = scales::rescale(pal_df$limit), 44 | limit = range(pal_df$limit), 45 | na.value = "lightblue" 46 | ) 47 | 48 | 49 | 50 | pal_df 51 | 52 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 53 | saveRDS(pal_df, extfile) 54 | -------------------------------------------------------------------------------- /data-raw/grass/srtm.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/srtm.rds -------------------------------------------------------------------------------- /data-raw/grass/srtm_plus.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "srtm_plus" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | tratapal <- init[-c(16:17)] %>% 13 | gsub(" ", ":", .) %>% 14 | lapply(strsplit, split = ":") 15 | 16 | pal_df <- lapply(tratapal, function(f) { 17 | tb <- as.double(unlist(f)) 18 | names(tb) <- c("limit", "r", "g", "b") 19 | df <- as.data.frame(t(tb)) 20 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 21 | df$pal <- pal 22 | 23 | df 24 | }) %>% 25 | bind_rows() %>% 26 | select(pal, limit, r, g, b, hex) 27 | 28 | pal_df 29 | 30 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 31 | saveRDS(pal_df, extfile) 32 | -------------------------------------------------------------------------------- /data-raw/grass/srtm_plus.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/srtm_plus.rds -------------------------------------------------------------------------------- /data-raw/grass/terrain.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "terrain" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | init 11 | 12 | 13 | tratapal <- init[-c(17)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)) 24 | names(tb) <- c("limit", "r", "g", "b") 25 | df <- as.data.frame(t(tb)) 26 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 27 | df$pal <- pal 28 | 29 | df 30 | }) %>% 31 | bind_rows() %>% 32 | select(pal, limit, r, g, b, hex) 33 | 34 | pal_df <- pal_df %>% 35 | group_by(limit) %>% 36 | slice_head(n = 1) 37 | 38 | 39 | # Try 40 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 41 | 42 | library(ggplot2) 43 | library(tidyterra) 44 | ggplot() + 45 | geom_spatraster(data = r) + 46 | scale_fill_gradientn( 47 | colours = pal_df$hex, 48 | values = scales::rescale(pal_df$limit), 49 | limit = range(pal_df$limit), 50 | na.value = "lightblue" 51 | ) 52 | 53 | 54 | 55 | 56 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 57 | saveRDS(pal_df, extfile) 58 | -------------------------------------------------------------------------------- /data-raw/grass/terrain.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/terrain.rds -------------------------------------------------------------------------------- /data-raw/grass/viridis.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "viridis" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | head(init, n = 10) 11 | 12 | 13 | tratapal <- init[-c(1:6)] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)[-1]) 24 | # tb2 <- col2rgb(tb[2]) %>% as.double() 25 | # tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/viridis.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/viridis.rds -------------------------------------------------------------------------------- /data-raw/grass/water.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "water" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | head(init, n = 10) 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)[-1]) 24 | # tb2 <- col2rgb(tb[2]) %>% as.double() 25 | # tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/water.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/water.rds -------------------------------------------------------------------------------- /data-raw/grass/wave.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | 3 | pal <- "wave" 4 | 5 | init <- readLines(paste0( 6 | "https://raw.githubusercontent.com/OSGeo/grass/main/", 7 | "lib/gis/colors/", pal 8 | )) 9 | 10 | head(init, n = 10) 11 | 12 | 13 | tratapal <- init[] %>% 14 | gsub(" ", " ", .) %>% 15 | gsub(" ", " ", .) %>% 16 | gsub(" ", " ", .) %>% 17 | gsub(" ", " ", .) %>% 18 | gsub(" ", ":", .) %>% 19 | gsub("aqua", paste0((col2rgb("aquamarine")), collapse = ":"), .) %>% 20 | lapply(strsplit, split = ":") 21 | 22 | pal_df <- lapply(tratapal, function(f) { 23 | tb <- as.double(unlist(f)[-1]) 24 | # tb2 <- col2rgb(tb[2]) %>% as.double() 25 | # tb <- as.double(tb2) 26 | 27 | names(tb) <- c("r", "g", "b") 28 | df <- as.data.frame(t(tb)) 29 | df$hex <- rgb(df$r, df$g, df$b, maxColorValue = 255) 30 | df$pal <- pal 31 | 32 | df 33 | }) %>% 34 | bind_rows() %>% 35 | select(pal, r, g, b, hex) 36 | 37 | # pal_df <- pal_df %>% 38 | # group_by(limit) %>% 39 | # slice_head(n = 1) %>% 40 | # arrange(limit) 41 | # 42 | 43 | # Try 44 | r <- terra::rast(system.file("extdata/asia.tif", package = "tidyterra")) 45 | 46 | library(ggplot2) 47 | library(tidyterra) 48 | ggplot() + 49 | geom_spatraster(data = r) + 50 | scale_fill_gradientn( 51 | colours = pal_df$hex, 52 | na.value = "lightblue" 53 | ) 54 | 55 | 56 | 57 | 58 | extfile <- paste0("./data-raw/grass/", pal, ".rds") 59 | saveRDS(pal_df, extfile) 60 | -------------------------------------------------------------------------------- /data-raw/grass/wave.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/grass/wave.rds -------------------------------------------------------------------------------- /data-raw/holyroodpark.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `holyroodpark` dataset goes here 2 | 3 | # Data from https://remotesensingdata.gov.scot/ 4 | # Scotland Lidar Phase 5 DSM NT27SE 5 | # License: https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/ 6 | 7 | 8 | library(terra) 9 | r <- rast("data-raw/dems/NT27SE_50CM_DSM_PHASE5.tif") 10 | 11 | # Cut to fit Holyrood Park 12 | hopark <- rast() 13 | 14 | ext(hopark) <- c(-3.178208, -3.142817, 55.939184, 55.95418) 15 | 16 | hopark <- project(hopark, terra::crs(r)) 17 | res(hopark) <- c(2.5, 2.5) 18 | 19 | final_rast <- terra::project(r, hopark) 20 | ncell(final_rast) 21 | names(final_rast) <- "elevation" 22 | plot(final_rast) 23 | # Extra clip 24 | xa <- 1000 25 | xb <- 200 26 | ya <- 300 27 | yb <- 300 28 | f2 <- as.vector(ext(final_rast)) 29 | f2_x <- f2 - c(xa, xb, ya, yb) 30 | 31 | xtraclip <- crop(final_rast, ext(f2_x)) 32 | plot(xtraclip) 33 | ncell(xtraclip) 34 | 35 | unlink("data-raw/holyroodpark.tif") 36 | unlink("vignettes/articles/holyroodpark.tif") 37 | writeRaster(xtraclip, "data-raw/holyroodpark.tif") 38 | writeRaster(xtraclip, "vignettes/articles/holyroodpark.tif") 39 | -------------------------------------------------------------------------------- /data-raw/holyroodpark.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/holyroodpark.tif -------------------------------------------------------------------------------- /data-raw/test_corine.R: -------------------------------------------------------------------------------- 1 | devtools::load_all() 2 | styler::style_pkg() 3 | 4 | usethis::use_test("keep_coltab") 5 | 6 | 7 | library(terra) 8 | 9 | r <- rast("data-raw/corine/U2018_CLC2018_V2020_20u1_FR_MTQ.tif") 10 | 11 | get_coltab_pal(r) 12 | autoplot(r) 13 | 14 | terra::has.colors(xend) 15 | 16 | pp <- as_tibble(r) %>% 17 | filter(substr(LABEL3, 1, 1) == "S") 18 | 19 | unique(pp$LABEL3) 20 | end <- unique(pp$LABEL3) 21 | as.integer(end) 22 | levels(pp$LABEL3) 23 | aa <- r %>% filter(substr(LABEL3, 1, 1) == "S") 24 | 25 | bb <- terra::levels(aa) 26 | 27 | fc <- factor(end, levels = levels(pp$LABEL3)) 28 | as.integer(fc) 29 | unique(terra::values(aa)) 30 | df <- terra::cats(r)[[1]] 31 | terra::coltab(aa) <- terra::coltab(r) 32 | cats(aa) 33 | terra::plot(aa) 34 | init <- terra::cats(r) 35 | end <- terra::cats(aa) 36 | terra::coltab(aa) 37 | get_coltab_pal(r) %>% scales::show_col() 38 | autoplot(aa) 39 | undebug(filter.SpatRaster) 40 | dplyr::tr 41 | glimpse(cats(r)[[1]]) 42 | 43 | r 44 | activeCat(r) 45 | autoplot(r) 46 | get_coltab_pal(r) 47 | x <- r 48 | y <- r 49 | activeCat(x) <- 5 50 | activeCat(y) <- 3 51 | 52 | p <- as.factor(letters) 53 | 54 | 55 | c(factor(p), factor(c("aa", "bb"))) 56 | 57 | ggplot() + 58 | geom_spatraster(data = y, aes(fill = after_stat(as.factor(value)))) 59 | 60 | 61 | scale_fill_coltab(y) 62 | 63 | coltab(y) 64 | get_coltab_pal(y) 65 | xend <- c(x, y) 66 | autoplot(y, use_coltab = FALSE) 67 | get_coltab_pal(xend) 68 | 69 | terra::cats(r) 70 | -------------------------------------------------------------------------------- /data-raw/unitsdb.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `unitsdb` dataset goes here 2 | ss <- load(file = "R/sysdata.rda") 3 | cat(ss) 4 | 5 | 6 | library(dplyr) 7 | 8 | udb <- units::valid_udunits() 9 | 10 | unitsdb <- udb %>% 11 | select(abb = symbol, name = name_singular) 12 | 13 | 14 | usethis::use_data(whitebox_coltab, unitsdb, overwrite = TRUE, internal = TRUE) 15 | -------------------------------------------------------------------------------- /data-raw/volcano2.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `volcano2` dataset goes here 2 | 3 | library(tidyverse) 4 | # library(elevatr) 5 | library(terra) 6 | library(tidyterra) 7 | 8 | allrast <- list.files("~/R/mapslib/misc/", pattern = "^DEM_BA32.*tif", full.names = TRUE) 9 | dem_list <- lapply(allrast, terra::rast) 10 | dem <- do.call(merge, dem_list) 11 | 12 | # Get extent from original raster 13 | forcrop <- terra::rast("inst/extdata/volcano2.tif") %>% 14 | terra::project(pull_crs(dem)) 15 | 16 | dem_crop <- terra::crop(dem, forcrop) 17 | 18 | terra::plot(dem_crop) 19 | 20 | # Resample to 5x5 21 | 22 | template <- terra::rast(dem_crop) 23 | res(template) <- c(5, 5) 24 | dem_crop <- terra::resample(dem_crop, template) 25 | 26 | volcano2 <- dem_crop 27 | 28 | 29 | terra::plot(volcano2) 30 | names(volcano2) <- "elevation" 31 | 32 | unlink("inst/extdata/volcano2.tif") 33 | writeRaster(volcano2, "inst/extdata/volcano2.tif") 34 | 35 | aa <- terra::rast("inst/extdata/volcano2.tif") 36 | 37 | terra::plot(aa) 38 | 39 | ggplot() + 40 | geom_spatraster_contour(data = aa) 41 | -------------------------------------------------------------------------------- /data-raw/volcano2.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/volcano2.tif -------------------------------------------------------------------------------- /data-raw/volcano2_dataset.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `volcano2` dataset goes here 2 | 3 | # Load DEM 4 | # From https://data.linz.govt.nz/layer/53405-auckland-lidar-1m-dem-2013/ 5 | # tiles: DEM_BA32_4001 to DEM_BA32_4003, DEM_BA32_4101 to DEM_BA32_4103 6 | devtools::load_all() 7 | # allzips <- list.files("~/R/mapslib/misc/", pattern = ".zip", full.names = TRUE) 8 | # 9 | # lapply(allzips, unzip, junkpaths=TRUE, exdir="~/R/mapslib/misc/") 10 | 11 | allrast <- list.files("~/R/mapslib/misc/", pattern = "^DEM_BA32.*tif", full.names = TRUE) 12 | dem_list <- lapply(allrast, terra::rast) 13 | dem <- do.call(merge, dem_list) 14 | 15 | # Get extent from original raster 16 | forcrop <- terra::rast("inst/extdata/volcano2.tif") %>% 17 | terra::project(pull_crs(dem)) 18 | 19 | dem_crop <- terra::crop(dem, forcrop) 20 | 21 | terra::plot(dem_crop) 22 | 23 | # Resample to 5x5 24 | 25 | template <- terra::rast(dem_crop) 26 | res(template) <- c(5, 5) 27 | dem_crop <- terra::resample(dem_crop, template) 28 | 29 | volcano2 <- terra::as.matrix(dem_crop, wide = TRUE) 30 | volcano2[is.na(volcano2)] <- NA 31 | class(volcano2) 32 | dim(volcano2) 33 | filled.contour(volcano2, color.palette = terrain.colors, asp = 1) 34 | 35 | terra::rast(volcano2) %>% terra::plot() 36 | dem_crop 37 | 38 | 39 | # class : SpatRaster 40 | # dimensions : 174, 122, 1 (nrow, ncol, nlyr) 41 | # resolution : 5, 5 (x, y) 42 | # extent : 1756969, 1757579, 5917003, 5917873 (xmin, xmax, ymin, ymax) 43 | # coord. ref. : NZGD2000 / New Zealand Transverse Mercator 2000 (EPSG:2193) 44 | # source : memory 45 | # name : DEM_BA32_4002_2013 46 | # min value : 76.26222 47 | # max value : 195.5542 48 | usethis::use_data(volcano2, overwrite = TRUE) 49 | 50 | 51 | # usethis::use_r("data") 52 | -------------------------------------------------------------------------------- /data-raw/volcano2hires.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data-raw/volcano2hires.tif -------------------------------------------------------------------------------- /data-raw/volcano_ok.R: -------------------------------------------------------------------------------- 1 | library(terra) 2 | library(ggplot2) 3 | devtools::load_all() 4 | 5 | allrast <- list.files("~/R/mapslib/misc/", pattern = "^DEM_BA32.*tif", full.names = TRUE) 6 | dem_list <- lapply(allrast, terra::rast) 7 | dem <- do.call(merge, dem_list) %>% drop_na() 8 | 9 | dem_end <- spatSample(dem, size = 500000, method = "regular", as.raster = TRUE) 10 | 11 | 12 | 13 | plot(dem_end) 14 | names(dem_end) <- "elevation" 15 | ncell(dem) 16 | ggplot() + 17 | geom_spatraster(data = dem_end) 18 | 19 | writeRaster(dem_end, "./data-raw/volcano2hires.tif") 20 | -------------------------------------------------------------------------------- /data/cross_blended_hypsometric_tints_db.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data/cross_blended_hypsometric_tints_db.rda -------------------------------------------------------------------------------- /data/grass_db.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data/grass_db.rda -------------------------------------------------------------------------------- /data/hypsometric_tints_db.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data/hypsometric_tints_db.rda -------------------------------------------------------------------------------- /data/princess_db.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data/princess_db.rda -------------------------------------------------------------------------------- /data/volcano2.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/data/volcano2.rda -------------------------------------------------------------------------------- /img/README-example-temp-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/img/README-example-temp-1.png -------------------------------------------------------------------------------- /img/README-example-temp-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/img/README-example-temp-2.png -------------------------------------------------------------------------------- /img/README-example-tile-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/img/README-example-tile-1.png -------------------------------------------------------------------------------- /img/README-example-tile-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/img/README-example-tile-2.png -------------------------------------------------------------------------------- /img/README-hypso-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/img/README-hypso-1.png -------------------------------------------------------------------------------- /img/README-hypso-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/img/README-hypso-2.png -------------------------------------------------------------------------------- /img/README-spatvec-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/img/README-spatvec-1.png -------------------------------------------------------------------------------- /img/spatraster-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/img/spatraster-example-1.png -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry( 2 | "Article", 3 | title = "Using the {tidyverse} with {terra} objects: the {tidyterra} package", 4 | doi = "10.21105/joss.05751", 5 | author = c(person("Diego", "Hernangómez")), 6 | year = "2023", 7 | url = "https://doi.org/10.21105/joss.05751", 8 | key = "R-tidyterra", 9 | publisher = "The Open Journal", 10 | volume = 8, 11 | number = 91, 12 | pages = 5751, 13 | journal = "Journal of Open Source Software", 14 | issn = "2475-9066", 15 | header = "If you use this software, please cite our article in the Journal of Open Source Software." 16 | ) 17 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | Acknowledgement 2 | Acknowledgements 3 | CMD 4 | CRS 5 | CodeFactor 6 | Colorimetric 7 | Coords 8 | DOI 9 | DSM 10 | EPSG 11 | ETOPO 12 | Geospatial 13 | Hijmans 14 | Holyrood 15 | Hypsometric 16 | ISSN 17 | JOSS 18 | LiDAR 19 | Licence 20 | Maungawhau 21 | NZGD 22 | ORCID 23 | PROJ 24 | Precompute 25 | RCzechia 26 | SpatRaster 27 | SpatVector 28 | Summarise 29 | Thorne 30 | Toitu 31 | Visualise 32 | WKT 33 | Whenua 34 | WhiteboxTools 35 | Wilke 36 | XY 37 | aesthethics 38 | bathymetric 39 | bathymetry 40 | behaviour 41 | binwidth 42 | biomod 43 | centimetres 44 | cli 45 | codecov 46 | coercible 47 | colour 48 | colours 49 | coltab 50 | coord 51 | cpt 52 | crs 53 | de 54 | dev 55 | disaggregated 56 | doi 57 | downsampled 58 | downup 59 | dplyr 60 | dtplyr 61 | ebvcuve 62 | fullseq 63 | geom's 64 | geoms 65 | gganimate 66 | ggplot 67 | ggproto 68 | ggspatial 69 | grey 70 | hypsometric 71 | hypsometry 72 | inlabru 73 | ish 74 | isoband 75 | isolines 76 | joss 77 | lon 78 | magrittr 79 | metR 80 | millimetres 81 | natively 82 | picas 83 | plotmath 84 | proj 85 | ptype 86 | purrr 87 | rasterVis 88 | rasters 89 | readr 90 | reprojected 91 | resamp 92 | rescaled 93 | rlang 94 | rst 95 | sparrpowR 96 | src 97 | srcs 98 | standardised 99 | summarise 100 | summarises 101 | summarising 102 | terra 103 | tibble 104 | tibbles 105 | tidyr 106 | tidyverse 107 | unevaluated 108 | ungroup 109 | ungrouped 110 | unmapped 111 | updown 112 | uri 113 | vectorised 114 | viridis 115 | visualise 116 | xmax 117 | xmin 118 | ymax 119 | ymin 120 | ️ 121 | -------------------------------------------------------------------------------- /inst/extdata/asia.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/inst/extdata/asia.tif -------------------------------------------------------------------------------- /inst/extdata/cyl.gpkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/inst/extdata/cyl.gpkg -------------------------------------------------------------------------------- /inst/extdata/cyl_elev.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/inst/extdata/cyl_elev.tif -------------------------------------------------------------------------------- /inst/extdata/cyl_era.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/inst/extdata/cyl_era.tif -------------------------------------------------------------------------------- /inst/extdata/cyl_temp.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/inst/extdata/cyl_temp.tif -------------------------------------------------------------------------------- /inst/extdata/cyl_tile.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/inst/extdata/cyl_tile.tif -------------------------------------------------------------------------------- /inst/extdata/volcano2.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/inst/extdata/volcano2.tif -------------------------------------------------------------------------------- /inst/schemaorg.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": "https://schema.org", 3 | "type": "SoftwareSourceCode", 4 | "author": { 5 | "id": "https://orcid.org/0000-0001-8457-4658" 6 | }, 7 | "codeRepository": "https://github.com/dieghernan/tidyterra", 8 | "contributor": [ 9 | { 10 | "id": "https://orcid.org/0000-0002-9415-4582", 11 | "type": "Person", 12 | "familyName": "Dunnington", 13 | "givenName": "Dewey" 14 | }, 15 | { 16 | "type": "Person", 17 | "familyName": "Manica", 18 | "givenName": "Andrea" 19 | } 20 | ], 21 | "copyrightHolder": [ 22 | { 23 | "id": "https://orcid.org/0000-0001-8457-4658", 24 | "type": "Person", 25 | "email": "diego.hernangomezherrero@gmail.com", 26 | "familyName": "Hernangómez", 27 | "givenName": "Diego" 28 | }, 29 | { 30 | "type": "Organization", 31 | "name": "ggplot2 authors" 32 | } 33 | ], 34 | "description": "Extension of the 'tidyverse' for 'SpatRaster' and 'SpatVector' objects of the 'terra' package. It includes also new 'geom_' functions that provide a convenient way of visualizing 'terra' objects with 'ggplot2'.", 35 | "license": "https://spdx.org/licenses/MIT", 36 | "name": "tidyterra: 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' Objects", 37 | "programmingLanguage": { 38 | "type": "ComputerLanguage", 39 | "name": "R", 40 | "url": "https://r-project.org" 41 | }, 42 | "provider": { 43 | "id": "https://cran.r-project.org", 44 | "type": "Organization", 45 | "name": "Comprehensive R Archive Network (CRAN)", 46 | "url": "https://cran.r-project.org" 47 | }, 48 | "runtimePlatform": "R version 4.5.0 (2025-04-11 ucrt)", 49 | "version": "0.7.2" 50 | } 51 | -------------------------------------------------------------------------------- /man/as_coordinates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/as_coordinates.R 3 | \name{as_coordinates} 4 | \alias{as_coordinates} 5 | \title{Get cell number, row and column from a \code{SpatRaster}} 6 | \usage{ 7 | as_coordinates(x, as.raster = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{A \code{SpatRaster} object.} 11 | 12 | \item{as.raster}{If \code{TRUE}, the result is a \code{SpatRaster} object with three 13 | layers indicating the position of each cell (cell number, row and column).} 14 | } 15 | \value{ 16 | A \code{\link[tibble:tibble]{tibble}} or a \code{SpatRaster} (if \code{as.raster = TRUE}) with 17 | the same number of rows (or cells) than the number of cells in \code{x}. 18 | 19 | When \code{as.raster = TRUE} the resulting \code{SpatRaster} has the same crs, 20 | extension and resolution than \code{x} 21 | } 22 | \description{ 23 | \code{as_coordinates()} can be used to obtain the position of each cell on the 24 | \code{SpatRaster} matrix. 25 | } 26 | \examples{ 27 | 28 | library(terra) 29 | 30 | f <- system.file("extdata/cyl_temp.tif", package = "tidyterra") 31 | 32 | r <- rast(f) 33 | 34 | as_coordinates(r) 35 | as_coordinates(r, as.raster = TRUE) 36 | 37 | as_coordinates(r, as.raster = TRUE) \%>\% plot() 38 | 39 | } 40 | \seealso{ 41 | \code{\link[=slice.SpatRaster]{slice.SpatRaster()}} 42 | 43 | Coercing objects: 44 | \code{\link{as_sf}()}, 45 | \code{\link{as_spatraster}()}, 46 | \code{\link{as_spatvector}()}, 47 | \code{\link{as_tibble.Spat}}, 48 | \code{\link{fortify.Spat}} 49 | } 50 | \concept{coerce} 51 | -------------------------------------------------------------------------------- /man/as_sf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/as_sf.R 3 | \name{as_sf} 4 | \alias{as_sf} 5 | \title{Coerce a \code{SpatVector} to a \code{\link[sf:sf]{sf}} object} 6 | \usage{ 7 | as_sf(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \code{SpatVector}.} 11 | 12 | \item{...}{additional arguments passed on to \code{\link[sf:st_as_sf]{sf::st_as_sf()}}.} 13 | } 14 | \value{ 15 | A \code{\link[sf:sf]{sf}} object object with an additional \code{tbl_df} class, for 16 | pretty printing method. 17 | } 18 | \description{ 19 | \code{\link[=as_sf]{as_sf()}} turns a \code{SpatVector} to \code{\link[sf:sf]{sf}} object. This is a wrapper 20 | of \code{\link[sf:st_as_sf]{sf::st_as_sf()}} with the particularity that the groups created with 21 | \code{\link[=group_by.SpatVector]{group_by.SpatVector()}} are preserved. 22 | } 23 | \examples{ 24 | 25 | library(terra) 26 | 27 | f <- system.file("extdata/cyl.gpkg", package = "tidyterra") 28 | v <- terra::vect(f) 29 | 30 | # This is ungrouped 31 | v 32 | is_grouped_spatvector(v) 33 | 34 | # Get an ungrouped data 35 | a_sf <- as_sf(v) 36 | 37 | dplyr::is_grouped_df(a_sf) 38 | 39 | # Grouped 40 | 41 | v$gr <- c("C", "A", "A", "B", "A", "B", "B") 42 | v$gr2 <- rep(c("F", "G", "F"), 3) 43 | 44 | gr_v <- group_by(v, gr, gr2) 45 | 46 | gr_v 47 | is_grouped_spatvector(gr_v) 48 | 49 | group_data(gr_v) 50 | 51 | # A sf 52 | 53 | a_gr_sf <- as_sf(gr_v) 54 | 55 | dplyr::is_grouped_df(a_gr_sf) 56 | 57 | group_data(a_gr_sf) 58 | 59 | } 60 | \seealso{ 61 | Coercing objects: 62 | \code{\link{as_coordinates}()}, 63 | \code{\link{as_spatraster}()}, 64 | \code{\link{as_spatvector}()}, 65 | \code{\link{as_tibble.Spat}}, 66 | \code{\link{fortify.Spat}} 67 | } 68 | \concept{coerce} 69 | -------------------------------------------------------------------------------- /man/figures/lifecycle-archived.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclearchivedarchived -------------------------------------------------------------------------------- /man/figures/lifecycle-defunct.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledefunctdefunct -------------------------------------------------------------------------------- /man/figures/lifecycle-deprecated.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledeprecateddeprecated -------------------------------------------------------------------------------- /man/figures/lifecycle-experimental.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycleexperimentalexperimental -------------------------------------------------------------------------------- /man/figures/lifecycle-maturing.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclematuringmaturing -------------------------------------------------------------------------------- /man/figures/lifecycle-questioning.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclequestioningquestioning -------------------------------------------------------------------------------- /man/figures/lifecycle-stable.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclestablestable -------------------------------------------------------------------------------- /man/figures/lifecycle-superseded.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclesupersededsuperseded -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/man/figures/logo.png -------------------------------------------------------------------------------- /man/is_grouped_spatvector.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/grouped-SpatVector.R 3 | \name{is_grouped_spatvector} 4 | \alias{is_grouped_spatvector} 5 | \title{A grouped \code{SpatVector}} 6 | \usage{ 7 | is_grouped_spatvector(x) 8 | } 9 | \arguments{ 10 | \item{x}{a \code{SpatVector}.} 11 | } 12 | \description{ 13 | The easiest way to create a grouped \code{SpatVector} is to call the 14 | \code{group_by()} method on a \code{SpatVector}: this will take care of capturing 15 | the unevaluated expressions for you. See \code{\link[=group_by.SpatVector]{group_by.SpatVector()}} for details. 16 | 17 | This function is the adapted version of \code{\link[dplyr:grouped_df]{dplyr::is_grouped_df()}}. 18 | 19 | See also \code{\link[=group_data.SpatVector]{group_data.SpatVector()}} for the accessory functions that retrieve 20 | various metadata from a grouped \code{SpatVector}. 21 | } 22 | \seealso{ 23 | Other helpers: 24 | \code{\link{compare_spatrasters}()}, 25 | \code{\link{is_regular_grid}()}, 26 | \code{\link{pull_crs}()} 27 | } 28 | \concept{helpers} 29 | \keyword{internal} 30 | -------------------------------------------------------------------------------- /man/is_regular_grid.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/is_regular_grid.R 3 | \name{is_regular_grid} 4 | \alias{is_regular_grid} 5 | \title{Check if x and y positions conforms a regular grid} 6 | \usage{ 7 | is_regular_grid(xy, digits = 6) 8 | } 9 | \arguments{ 10 | \item{xy}{A matrix, data frame or tibble of at least two columns representing 11 | x and y coordinates.} 12 | 13 | \item{digits}{integer to set the precision for detecting whether points are 14 | on a regular grid (a low number of digits is a low precision).} 15 | } 16 | \value{ 17 | \code{invisible()} if is regular or an error message otherwise 18 | } 19 | \description{ 20 | Assess if the coordinates x,y of an object conforms a regular grid. This 21 | function is called by its side effects. 22 | 23 | This function is internally called by \code{\link[=as_spatraster]{as_spatraster()}}. 24 | } 25 | \examples{ 26 | 27 | p <- matrix(1:90, nrow = 45, ncol = 2) 28 | 29 | is_regular_grid(p) 30 | 31 | 32 | # Jitter location 33 | set.seed(1234) 34 | jitter <- runif(length(p)) / 10e4 35 | p_jitter <- p + jitter 36 | 37 | # Need to adjust digits 38 | is_regular_grid(p_jitter, digits = 4) 39 | 40 | } 41 | \seealso{ 42 | \code{\link[=as_spatraster]{as_spatraster()}} 43 | 44 | Other helpers: 45 | \code{\link{compare_spatrasters}()}, 46 | \code{\link{is_grouped_spatvector}()}, 47 | \code{\link{pull_crs}()} 48 | } 49 | \concept{helpers} 50 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \arguments{ 10 | \item{lhs}{A value or the magrittr placeholder.} 11 | 12 | \item{rhs}{A function call using the magrittr semantics.} 13 | } 14 | \value{ 15 | The result of calling \code{rhs(lhs)}. 16 | } 17 | \description{ 18 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/princess_db.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{princess_db} 5 | \alias{princess_db} 6 | \title{Princess palettes database} 7 | \format{ 8 | A \code{\link[tibble:tibble]{tibble}} of 75 rows and 9 | 5 columns. with the following fields: 10 | 11 | \describe{ 12 | \item{pal}{ Name of the palette.} 13 | \item{r}{Value of the red channel (RGB color mode).} 14 | \item{g}{Value of the green channel (RGB color mode).} 15 | \item{b}{Value of the blue channel (RGB color mode).} 16 | \item{hex}{ Hex code of the color.} 17 | } 18 | } 19 | \source{ 20 | \url{https://leahsmyth.github.io/Princess-Colour-Schemes/index.html}. 21 | } 22 | \description{ 23 | A \code{\link[tibble:tibble]{tibble}} including the color map of 24 | 15 gradient palettes. 25 | } 26 | \examples{ 27 | \donttest{ 28 | data("princess_db") 29 | 30 | princess_db 31 | 32 | # Select a palette 33 | maori <- princess_db \%>\% 34 | filter(pal == "maori") 35 | 36 | f <- system.file("extdata/volcano2.tif", package = "tidyterra") 37 | r <- terra::rast(f) 38 | 39 | library(ggplot2) 40 | 41 | p <- ggplot() + 42 | geom_spatraster(data = r) + 43 | labs(fill = "elevation") 44 | 45 | p + 46 | scale_fill_gradientn(colors = maori$hex) 47 | } 48 | } 49 | \seealso{ 50 | \code{\link[=scale_fill_princess_c]{scale_fill_princess_c()}} 51 | 52 | Other datasets: 53 | \code{\link{cross_blended_hypsometric_tints_db}}, 54 | \code{\link{grass_db}}, 55 | \code{\link{hypsometric_tints_db}}, 56 | \code{\link{volcano2}} 57 | } 58 | \concept{datasets} 59 | -------------------------------------------------------------------------------- /man/replace_na.Spat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/replace_na-Spat.R 3 | \name{replace_na.Spat} 4 | \alias{replace_na.Spat} 5 | \alias{replace_na.SpatRaster} 6 | \alias{replace_na.SpatVector} 7 | \title{Replace \code{NA}s with specified values} 8 | \usage{ 9 | \method{replace_na}{SpatRaster}(data, replace = list(), ...) 10 | 11 | \method{replace_na}{SpatVector}(data, replace, ...) 12 | } 13 | \arguments{ 14 | \item{data}{A \code{SpatRaster} created with \code{\link[terra:rast]{terra::rast()}} or a \code{SpatVector} 15 | created with \code{\link[terra:vect]{terra::vect()}}.} 16 | 17 | \item{replace}{list of values, with one value for each layer/attribute that 18 | has \code{NA} values to be replaced.} 19 | 20 | \item{...}{Ignored} 21 | } 22 | \value{ 23 | A \verb{Spat*} object of the same class than \code{data}. Geometries and 24 | spatial attributes are preserved. 25 | } 26 | \description{ 27 | Replace \code{NA} values on layers/attributes with specified values 28 | } 29 | \section{\CRANpkg{terra} equivalent}{ 30 | 31 | 32 | Use \verb{r[is.na(r)] <- } 33 | } 34 | 35 | \examples{ 36 | 37 | library(terra) 38 | 39 | f <- system.file("extdata/cyl_temp.tif", package = "tidyterra") 40 | r <- rast(f) 41 | 42 | r \%>\% plot() 43 | 44 | r \%>\% 45 | replace_na(list(tavg_04 = 6, tavg_06 = 20)) \%>\% 46 | plot() 47 | 48 | } 49 | \seealso{ 50 | \code{\link[tidyr:replace_na]{tidyr::replace_na()}} 51 | 52 | Other \CRANpkg{tidyr} verbs for handling missing values: 53 | \code{\link{drop_na.Spat}}, 54 | \code{\link{fill.SpatVector}()} 55 | 56 | Other \CRANpkg{tidyr} methods: 57 | \code{\link{drop_na.Spat}}, 58 | \code{\link{fill.SpatVector}()}, 59 | \code{\link{pivot_longer.SpatVector}()}, 60 | \code{\link{pivot_wider.SpatVector}()} 61 | } 62 | \concept{tidyr.methods} 63 | \concept{tidyr.missing} 64 | -------------------------------------------------------------------------------- /man/roxygen/meta.R: -------------------------------------------------------------------------------- 1 | list( 2 | rd_family_title = list( 3 | coerce = "Coercing objects:", 4 | tibble.methods = "Other \\CRANpkg{tibble} methods:", 5 | dplyr.methods = "Other \\CRANpkg{dplyr} methods:", 6 | dplyr.rows = "Other \\CRANpkg{dplyr} verbs that operate on rows:", 7 | dplyr.cols = "Other \\CRANpkg{dplyr} verbs that operate on columns:", 8 | dplyr.groups = paste0( 9 | "Other \\CRANpkg{dplyr} verbs that operate on ", 10 | "group of rows:" 11 | ), 12 | dplyr.pairs = paste0( 13 | "Other \\CRANpkg{dplyr} verbs that operate on ", 14 | "pairs \\code{Spat*}/data.frame:" 15 | ), 16 | tidyr.methods = "Other \\CRANpkg{tidyr} methods:", 17 | tidyr.pivot = "Other \\CRANpkg{tidyr} verbs for pivoting:", 18 | tidyr.missing = paste0( 19 | "Other \\CRANpkg{tidyr} verbs for handling ", 20 | "missing values:" 21 | ), 22 | ggplot2.utils = "Other \\CRANpkg{ggplot2} utils:", 23 | ggplot2.methods = "Other \\CRANpkg{ggplot2} methods:", 24 | joins = "Other joins:", 25 | grouping = "Other grouping functions:", 26 | gradients = "Other gradient scales and palettes for hypsometry:" 27 | ) 28 | ) 29 | -------------------------------------------------------------------------------- /man/tidyterra-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidyterra-package.R 3 | \docType{package} 4 | \name{tidyterra-package} 5 | \alias{tidyterra} 6 | \alias{tidyterra-package} 7 | \title{tidyterra: 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' Objects} 8 | \description{ 9 | \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} 10 | 11 | Extension of the 'tidyverse' for 'SpatRaster' and 'SpatVector' objects of the 'terra' package. It includes also new 'geom_' functions that provide a convenient way of visualizing 'terra' objects with 'ggplot2'. 12 | } 13 | \seealso{ 14 | Useful links: 15 | \itemize{ 16 | \item \url{https://dieghernan.github.io/tidyterra/} 17 | \item \url{https://github.com/dieghernan/tidyterra} 18 | \item Report bugs at \url{https://github.com/dieghernan/tidyterra/issues} 19 | } 20 | 21 | } 22 | \author{ 23 | \strong{Maintainer}: Diego Hernangómez \email{diego.hernangomezherrero@gmail.com} (\href{https://orcid.org/0000-0001-8457-4658}{ORCID}) [copyright holder] 24 | 25 | Other contributors: 26 | \itemize{ 27 | \item Dewey Dunnington (\href{https://orcid.org/0000-0002-9415-4582}{ORCID}) (for ggspatial code) [contributor] 28 | \item ggplot2 authors (for contour code) [copyright holder] 29 | \item Andrea Manica [contributor] 30 | } 31 | 32 | } 33 | \keyword{internal} 34 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/pkgdown/favicon/favicon-96x96.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /pkgdown/favicon/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "short_name": "", 4 | "icons": [ 5 | { 6 | "src": "/web-app-manifest-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png", 9 | "purpose": "maskable" 10 | }, 11 | { 12 | "src": "/web-app-manifest-512x512.png", 13 | "sizes": "512x512", 14 | "type": "image/png", 15 | "purpose": "maskable" 16 | } 17 | ], 18 | "theme_color": "#ffffff", 19 | "background_color": "#ffffff", 20 | "display": "standalone" 21 | } -------------------------------------------------------------------------------- /pkgdown/favicon/web-app-manifest-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/pkgdown/favicon/web-app-manifest-192x192.png -------------------------------------------------------------------------------- /pkgdown/favicon/web-app-manifest-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/pkgdown/favicon/web-app-manifest-512x512.png -------------------------------------------------------------------------------- /revdep/.gitignore: -------------------------------------------------------------------------------- 1 | checks 2 | library 3 | checks.noindex 4 | library.noindex 5 | data.sqlite 6 | *.html 7 | -------------------------------------------------------------------------------- /revdep/cran.md: -------------------------------------------------------------------------------- 1 | ## revdepcheck results 2 | 3 | We checked 29 reverse dependencies (0 from CRAN + 29 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package. 4 | 5 | * We saw 0 new problems 6 | * We failed to check 0 packages 7 | 8 | -------------------------------------------------------------------------------- /revdep/failures.md: -------------------------------------------------------------------------------- 1 | # ebvcube 2 | 3 |
4 | 5 | * Version: 6 | * GitHub: https://github.com/dieghernan/tidyterra 7 | * Source code: NA 8 | * Number of recursive dependencies: 0 9 | 10 |
11 | 12 | ## Error before installation 13 | 14 | ### Devel 15 | 16 | ``` 17 | 18 | 19 | 20 | 21 | 22 | 23 | ``` 24 | ### CRAN 25 | 26 | ``` 27 | 28 | 29 | 30 | 31 | 32 | 33 | ``` 34 | -------------------------------------------------------------------------------- /revdep/problems.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview 7 | # * https://testthat.r-lib.org/articles/special-files.html 8 | 9 | library(testthat) 10 | library(tidyterra) 11 | 12 | test_check("tidyterra") 13 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/as_coordinates.md: -------------------------------------------------------------------------------- 1 | # as_coordinates errors 2 | 3 | Code 4 | as_coordinates(v) 5 | Condition 6 | Error in `as_coordinates()`: 7 | ! `tidyterra::as_coordinates()` needs a object, not a object 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/as_sf.md: -------------------------------------------------------------------------------- 1 | # Only works with SpatVector 2 | 3 | Code 4 | as_sf(r) 5 | Condition 6 | Error in `as_sf()`: 7 | ! `x` is a not a 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/as_spatraster.md: -------------------------------------------------------------------------------- 1 | # Error check 2 | 3 | Code 4 | as_spatraster(as_tbl, xycols = 2) 5 | Condition 6 | Error in `as_spatraster()`: 7 | ! `xycols` should have a length of 2, not 1 8 | 9 | --- 10 | 11 | Code 12 | as_spatraster(as_tbl, xycols = c("x", "y")) 13 | Condition 14 | Error in `as_spatraster()`: 15 | ! `xycols` should be a , not 16 | 17 | --- 18 | 19 | Code 20 | as_spatraster(as_tbl, xycols = 1:3) 21 | Condition 22 | Error in `as_spatraster()`: 23 | ! `xycols` should have a length of 2, not 3 24 | 25 | --- 26 | 27 | Code 28 | as_spatraster(as.matrix(as_tbl)) 29 | Condition 30 | Error in `as_spatraster()`: 31 | ! `x` should be a , not 32 | 33 | # Regenerate raster properly 34 | 35 | Code 36 | res <- compare_spatrasters(r, fromnonatr) 37 | Message 38 | ! Results of `tidyterra::compare_spatrasters()`: 39 | The following attributes are not equal: 40 | * crs 41 | 42 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/as_spatvector.md: -------------------------------------------------------------------------------- 1 | # Error check 2 | 3 | Code 4 | as_spatvector(as_tbl) 5 | Condition 6 | Error in `as_spatvector()`: 7 | ! Columns `lon` and `lat` not found in `x` 8 | 9 | --- 10 | 11 | Code 12 | as_spatvector(as_tbl, geom = NA) 13 | Condition 14 | Error in `as_spatvector()`: 15 | ! `geom` should be a , not 16 | 17 | --- 18 | 19 | Code 20 | as_spatvector(as_tbl, geom = c("a", "b", "c")) 21 | Condition 22 | Error in `as_spatvector()`: 23 | ! `geom` should be of length 1 or 2, not 3 24 | 25 | --- 26 | 27 | Code 28 | as_spatvector(as_tbl, geom = 1) 29 | Condition 30 | Error in `as_spatvector()`: 31 | ! `geom` should be a , not 32 | 33 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/as_tibble-Spat.md: -------------------------------------------------------------------------------- 1 | # For SpatVector 2 | 3 | Code 4 | res <- dplyr::as_tibble(v2, geom = "WKT") 5 | Message 6 | i Column(s) with duplicated/reserved names detected. See About layer/column 7 | names section on `tidyterra::as_tibble.SpatRaster()` 8 | ! Renaming columns: 9 | Output 10 | * `geometry` -> `geometry.1` 11 | 12 | --- 13 | 14 | Code 15 | res <- dplyr::as_tibble(v2, geom = "HEX") 16 | Message 17 | i Column(s) with duplicated/reserved names detected. See About layer/column 18 | names section on `tidyterra::as_tibble.SpatRaster()` 19 | ! Renaming columns: 20 | Output 21 | * `geometry` -> `geometry.1` 22 | 23 | --- 24 | 25 | Code 26 | res_p <- dplyr::as_tibble(p, geom = "XY") 27 | Message 28 | i Column(s) with duplicated/reserved names detected. See About layer/column 29 | names section on `tidyterra::as_tibble.SpatRaster()` 30 | ! Renaming columns: 31 | Output 32 | * `x` -> `x.1` 33 | * `y` -> `y.1` 34 | 35 | # For SpatVector internal 36 | 37 | Code 38 | as_tbl_internal(ntibble) 39 | Condition 40 | Error in `as_tbl_internal()`: 41 | ! `x` is not of or object 42 | 43 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/autoplot-Spat.md: -------------------------------------------------------------------------------- 1 | # Test SpatRaster 2 | 3 | Code 4 | b <- ggplot2::ggplot_build(forced) 5 | Message 6 | ! `tidyterra::geom_spatraster()`: Plotting 4 overlapping layers: tavg_04, tavg_05, tavg_06, and other. Either: 7 | Use `facet_wrap(~lyr)` for faceting or 8 | Use `aes(fill = )` for displaying single layers 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/bind-cols-SpatVector.md: -------------------------------------------------------------------------------- 1 | # bind_spat_cols() repairs names 2 | 3 | Code 4 | bound <- bind_spat_cols(df, df) 5 | Message 6 | New names: 7 | * `a` -> `a...1` 8 | * `b` -> `b...2` 9 | * `a` -> `a...3` 10 | * `b` -> `b...4` 11 | 12 | --- 13 | 14 | Code 15 | repaired <- tibble::as_tibble(data.frame(a = 1, b = 2, a = 1, b = 2, 16 | check.names = FALSE), .name_repair = "unique") 17 | Message 18 | New names: 19 | * `a` -> `a...1` 20 | * `b` -> `b...2` 21 | * `a` -> `a...3` 22 | * `b` -> `b...4` 23 | 24 | # bind_spat_cols() honours .name_repair= 25 | 26 | Code 27 | res <- bind_spat_cols(aa, data.frame(a = 2)) 28 | Message 29 | New names: 30 | * `a` -> `a...1` 31 | * `a` -> `a...2` 32 | 33 | # bind_spat_cols() gives informative errors 34 | 35 | Code 36 | # # incompatible size 37 | (expect_error(bind_spat_cols(mtcars))) 38 | Output 39 | 40 | Error in `bind_spat_cols()`: 41 | ! Object 1 in `...` is not a 42 | 43 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/compare_spatrasters.md: -------------------------------------------------------------------------------- 1 | # Error 2 | 3 | Code 4 | compare_spatrasters(x, terra::crs(x)) 5 | Condition 6 | Error in `compare_spatrasters()`: 7 | ! `x` and `y` must be s. `x` is , `y` is 8 | 9 | --- 10 | 11 | Code 12 | compare_spatrasters(1, "a") 13 | Condition 14 | Error in `compare_spatrasters()`: 15 | ! `x` and `y` must be s. `x` is , `y` is 16 | 17 | # Different crs 18 | 19 | Code 20 | res <- compare_spatrasters(x, y) 21 | Message 22 | ! Results of `tidyterra::compare_spatrasters()`: 23 | The following attributes are not equal: 24 | * crs 25 | 26 | # Different extent 27 | 28 | Code 29 | res <- compare_spatrasters(x, y) 30 | Message 31 | ! Results of `tidyterra::compare_spatrasters()`: 32 | The following attributes are not equal: 33 | * extent 34 | 35 | # Different resolution 36 | 37 | Code 38 | res <- compare_spatrasters(x, y) 39 | Message 40 | ! Results of `tidyterra::compare_spatrasters()`: 41 | The following attributes are not equal: 42 | * resolution 43 | 44 | # All different 45 | 46 | Code 47 | res <- compare_spatrasters(x, y) 48 | Message 49 | ! Results of `tidyterra::compare_spatrasters()`: 50 | The following attributes are not equal: 51 | * crs 52 | * extent 53 | * resolution 54 | 55 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/distinct-SpatVector.md: -------------------------------------------------------------------------------- 1 | # Name handling 2 | 3 | Code 4 | expect_message(vall <- distinct(v), "with duplicated/reserved") 5 | Message 6 | ! Renaming columns: 7 | Output 8 | * `geometry` -> `geometry.1` 9 | Message 10 | i Column(s) with duplicated/reserved names detected. See About layer/column 11 | names section on `tidyterra::as_tibble.SpatRaster()` 12 | ! Renaming columns: 13 | Output 14 | * `geometry` -> `geometry.1` 15 | 16 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/drop_na-Spat.md: -------------------------------------------------------------------------------- 1 | # Return empty geom when no results 2 | 3 | Code 4 | empty <- drop_na(v) 5 | Message 6 | ! All geometries dropped. 7 | Returning empty 8 | 9 | --- 10 | 11 | Code 12 | emptycrs <- drop_na(nocrs) 13 | Message 14 | ! All geometries dropped. 15 | Returning empty 16 | 17 | # Drop na with SpatRaster 18 | 19 | Code 20 | res <- compare_spatrasters(r, all) 21 | Message 22 | ! Results of `tidyterra::compare_spatrasters()`: 23 | The following attributes are not equal: 24 | * extent 25 | 26 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/fortify-Spat.md: -------------------------------------------------------------------------------- 1 | # Fortify SpatRasters pivot 2 | 3 | Code 4 | aa <- fortify(fort2, pivot = TRUE) 5 | Condition 6 | Warning: 7 | Mixed layer classes found in `tidyterra::fortify.SpatRaster()`. 8 | Message 9 | ! Plotting only layer "tavg_04", "tavg_05", and "tavg_06" of class 10 | 11 | # Fortify SpatRasters pivot factor 12 | 13 | Code 14 | end <- check_mixed_cols(s_r_f_mix) 15 | Condition 16 | Warning: 17 | Mixed layer classes found in `tidyterra::geom_spat*()`. 18 | Message 19 | ! Plotting only layer "r1/r1", "r1/r2", "r2/r1", and "r2/r2" of class 20 | 21 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/geom_spat_contour.md: -------------------------------------------------------------------------------- 1 | # Errors and messages 2 | 3 | Code 4 | ggplot() + geom_spatraster_contour(data = v) 5 | Condition 6 | Error in `geom_spatraster_contour()`: 7 | ! `tidyterra::geom_spatraster_contour()` only works with objects, not . See `?terra::vect()` 8 | 9 | --- 10 | 11 | Code 12 | ggplot() + geom_spatraster_contour(data = 1:3) 13 | Condition 14 | Error in `geom_spatraster_contour()`: 15 | ! `tidyterra::geom_spatraster_contour()` only works with objects, not . See `?terra::vect()` 16 | 17 | --- 18 | 19 | Code 20 | ggplot() + geom_spatraster_contour(data = r, aes(z = noexist)) 21 | Condition 22 | Error in `geom_spatraster_contour()`: 23 | ! Layer "noexist" not found in `data` 24 | 25 | --- 26 | 27 | Code 28 | end <- ggplot_build(ff) 29 | Condition 30 | Warning: 31 | In `tidyterra::geom_spatraster_contour()`: Zero contours were generated 32 | Warning in `min()`: 33 | no non-missing arguments to min; returning Inf 34 | Warning in `max()`: 35 | no non-missing arguments to max; returning -Inf 36 | Warning: 37 | Computation failed in `stat_terra_spat_raster_contour()`. 38 | Caused by error in `$<-.data.frame`: 39 | ! replacement has 1 row, data has 0 40 | 41 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/geom_spat_contour_text.md: -------------------------------------------------------------------------------- 1 | # Errors and messages 2 | 3 | Code 4 | ggplot() + geom_spatraster_contour_text(data = v) 5 | Condition 6 | Error in `geom_spatraster_contour_text()`: 7 | ! `tidyterra::geom_spatraster_contour_text()` only works with objects, not . See `?terra::vect()` 8 | 9 | --- 10 | 11 | Code 12 | ggplot() + geom_spatraster_contour_text(data = 1:3) 13 | Condition 14 | Error in `geom_spatraster_contour_text()`: 15 | ! `tidyterra::geom_spatraster_contour_text()` only works with objects, not . See `?terra::vect()` 16 | 17 | --- 18 | 19 | Code 20 | ggplot() + geom_spatraster_contour_text(data = r, aes(z = noexist)) 21 | Condition 22 | Error in `geom_spatraster_contour_text()`: 23 | ! Layer "noexist" not found in `data` 24 | 25 | --- 26 | 27 | Code 28 | end <- ggplot_build(ff) 29 | 30 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/geom_spatraster_1lyr.md: -------------------------------------------------------------------------------- 1 | # geom_spatraster one layer with CRS 2 | 3 | Code 4 | ggplot() + geom_spatraster(data = v) 5 | Condition 6 | Error in `geom_spatraster()`: 7 | ! `tidyterra::geom_spatraster()` only works with objects, not . See `?terra::vect()` 8 | 9 | --- 10 | 11 | Code 12 | ggplot() + geom_spatraster(data = 1:3) 13 | Condition 14 | Error in `geom_spatraster()`: 15 | ! `tidyterra::geom_spatraster()` only works with objects, not . See `?terra::vect()` 16 | 17 | --- 18 | 19 | Code 20 | p_res <- ggplot() + geom_spatraster(data = r, maxcell = 20) 21 | Message 22 | resampled to 24 cells. 23 | 24 | --- 25 | 26 | Code 27 | p_res_int <- ggplot() + geom_spatraster(data = r, maxcell = 20, interpolate = TRUE) 28 | Message 29 | resampled to 24 cells. 30 | 31 | # geom_spatraster one layer without CRS 32 | 33 | Code 34 | p_res <- ggplot() + geom_spatraster(data = r, maxcell = 20) 35 | Message 36 | resampled to 24 cells. 37 | 38 | --- 39 | 40 | Code 41 | p_res_int <- ggplot() + geom_spatraster(data = r, maxcell = 20, interpolate = TRUE) 42 | Message 43 | resampled to 24 cells. 44 | 45 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/geom_spatraster_1lyr_coltab.md: -------------------------------------------------------------------------------- 1 | # geom_spatraster one layer coltab with CRS 2 | 3 | Code 4 | lydata <- layer_data(st1) 5 | Condition 6 | Warning: 7 | No shared levels found between `names(values)` of the manual scale and the data's fill values. 8 | Warning: 9 | No shared levels found between `names(values)` of the manual scale and the data's fill values. 10 | 11 | # geom_spatraster one layer without CRS 12 | 13 | Code 14 | lydata <- layer_data(st1) 15 | Condition 16 | Warning: 17 | No shared levels found between `names(values)` of the manual scale and the data's fill values. 18 | Warning: 19 | No shared levels found between `names(values)` of the manual scale and the data's fill values. 20 | 21 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/geom_spatraster_3lyr_coltab.md: -------------------------------------------------------------------------------- 1 | # geom_spatraster several layer with CRS 2 | 3 | Code 4 | pp <- ggplot2::ggplot_build(p) 5 | Message 6 | ! `tidyterra::geom_spatraster()`: Plotting 3 overlapping layers: cut1, cut2, and cut3. Either: 7 | Use `facet_wrap(~lyr)` for faceting or 8 | Use `aes(fill = )` for displaying single layers 9 | 10 | --- 11 | 12 | Code 13 | p_cats <- ggplot() + geom_spatraster(data = r) + facet_wrap(~lyr) + 14 | scale_fill_terrain_d() 15 | Message 16 | Scale for fill is already present. 17 | Adding another scale for fill, which will replace the existing scale. 18 | 19 | --- 20 | 21 | Code 22 | pmix1 <- ggplot() + geom_spatraster(data = r_mix1) + facet_wrap(~lyr) 23 | Condition 24 | Warning: 25 | Mixed layer classes found in `tidyterra::geom_spat*()`. 26 | Message 27 | ! Plotting only layer "cut1", "cut2", and "cut3" of class 28 | 29 | --- 30 | 31 | Code 32 | p_res <- ggplot() + geom_spatraster(data = r, maxcell = 20) + facet_wrap(~lyr) 33 | Message 34 | resampled to 24 cells. 35 | 36 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/geom_spatraster_rgb.md: -------------------------------------------------------------------------------- 1 | # geom_spatraster_rgb with CRS 2 | 3 | Code 4 | ggplot() + geom_spatraster_rgb(data = v) 5 | Condition 6 | Error in `geom_spatraster_rgb()`: 7 | ! `tidyterra::geom_spatraster_rgb()` only works with objects, not . See `?terra::vect()` 8 | 9 | --- 10 | 11 | Code 12 | ggplot() + geom_spatraster_rgb(data = 1:3) 13 | Condition 14 | Error in `geom_spatraster_rgb()`: 15 | ! `tidyterra::geom_spatraster_rgb()` only works with objects, not . See `?terra::vect()` 16 | 17 | --- 18 | 19 | Code 20 | ggplot() + geom_spatraster_rgb(data = r_subset) 21 | Condition 22 | Error in `geom_spatraster_rgb()`: 23 | ! Incorrect number of layers on `r`, `g`, and `b`. data has 2 layers. 24 | 25 | --- 26 | 27 | Code 28 | ggplot() + geom_spatraster_rgb(data = r_subset %>% select(1)) 29 | Condition 30 | Error in `geom_spatraster_rgb()`: 31 | ! Incorrect number of layers on `r`, `g`, and `b`. data has 1 layer. 32 | 33 | --- 34 | 35 | Code 36 | p_res <- ggplot() + geom_spatraster_rgb(data = r, maxcell = 20) 37 | Message 38 | resampled to 25 cells. 39 | 40 | --- 41 | 42 | Code 43 | p_res_int <- ggplot() + geom_spatraster_rgb(data = r, maxcell = 20, 44 | interpolate = TRUE) 45 | Message 46 | resampled to 25 cells. 47 | 48 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/group-by-SpatVector-terra.md: -------------------------------------------------------------------------------- 1 | # Gives meaningful messages 2 | 3 | Code 4 | gr_v2 <- gr_v2 %>% mutate(a = 1) 5 | Message 6 | ! `tidyterra::group_vars.SpatVector()` missing on data. Have you mixed terra and tidyterra syntax? 7 | i Ungrouping data 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/join-SpatVector.md: -------------------------------------------------------------------------------- 1 | # Test errors 2 | 3 | Code 4 | inner_join(df1, df1) 5 | Condition 6 | Error in `error_spat_join()`: 7 | ! `y` should not be . For spatial joins use `terra::intersect()` 8 | 9 | --- 10 | 11 | Code 12 | left_join(df1, df1) 13 | Condition 14 | Error in `error_spat_join()`: 15 | ! `y` should not be . For spatial joins use `terra::intersect()` 16 | 17 | --- 18 | 19 | Code 20 | right_join(df1, df1) 21 | Condition 22 | Error in `error_spat_join()`: 23 | ! `y` should not be . For spatial joins use `terra::intersect()` 24 | 25 | --- 26 | 27 | Code 28 | semi_join(df1, sf::st_as_sf(df1)) 29 | Condition 30 | Error in `error_spat_join()`: 31 | ! `y` should not be . For spatial joins use `terra::intersect()` 32 | 33 | --- 34 | 35 | Code 36 | anti_join(df1, df1) 37 | Condition 38 | Error in `error_spat_join()`: 39 | ! `y` should not be . For spatial joins use `terra::intersect()` 40 | 41 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/mutate-Spat.md: -------------------------------------------------------------------------------- 1 | # SpatRaster mutate and check names 2 | 3 | Code 4 | fixed_names <- dplyr::mutate(spatrast, b2 = a + 100) 5 | Message 6 | i Layer(s) with duplicated/reserved names detected. See About layer/column 7 | names section on `tidyterra::as_tibble.SpatRaster()` 8 | ! Renaming columns: 9 | Output 10 | * `a` -> `a.1` 11 | 12 | --- 13 | 14 | Code 15 | fixed_names2 <- dplyr::mutate(spatrast, b2 = x.1 + x.2 + y.1) 16 | Message 17 | i Layer(s) with duplicated/reserved names detected. See About layer/column 18 | names section on `tidyterra::as_tibble.SpatRaster()` 19 | ! Renaming columns: 20 | Output 21 | * `x` -> `x.1` 22 | * `x` -> `x.2` 23 | * `y` -> `y.1` 24 | 25 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/pivot-long-SpatVector.md: -------------------------------------------------------------------------------- 1 | # can handle missing combinations 2 | 3 | Code 4 | pv <- pivot_longer(df, -id, names_to = c(".value", "n"), names_sep = "_") 5 | Message 6 | ! Ommiting "geometry" column from `cols` argument. 7 | 8 | # original col order is preserved 9 | 10 | Code 11 | pv <- pivot_longer(df, -id, names_to = c(".value", "n"), names_sep = "_") 12 | Message 13 | ! Ommiting "geometry" column from `cols` argument. 14 | 15 | # can pivot duplicated names to .value 16 | 17 | Code 18 | pv1 <- pivot_longer(df, -x, names_to = c(".value", NA), names_sep = "_") 19 | Message 20 | ! Ommiting "geometry" column from `cols` argument. 21 | 22 | # Check tidyselect: var1:var10 23 | 24 | Code 25 | out <- remove_geom_col(tbl, a:char, "test_that") 26 | Message 27 | ! Ommiting "geometry" column from `test_that` argument. 28 | 29 | # Check tidyselect: start_with 30 | 31 | Code 32 | out <- remove_geom_col(tbl, dplyr::starts_with("g"), "test_that") 33 | Message 34 | ! Ommiting "geometry" column from `test_that` argument. 35 | 36 | # Check tidyselect: ends_with 37 | 38 | Code 39 | out <- remove_geom_col(tbl, dplyr::ends_with("y"), "test_that") 40 | Message 41 | ! Ommiting "geometry" column from `test_that` argument. 42 | 43 | --- 44 | 45 | Code 46 | out <- remove_geom_col(tbl, dplyr::ends_with("y"), "test_that") 47 | Message 48 | ! Ommiting "geometry" column from `test_that` argument. 49 | 50 | # Check tidyselect: whereis 51 | 52 | Code 53 | out <- remove_geom_col(tbl, dplyr::where(is.character), "test_that") 54 | Message 55 | ! Ommiting "geometry" column from `test_that` argument. 56 | 57 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/pivot-wide-SpatVector.md: -------------------------------------------------------------------------------- 1 | # Remove geometry from values 2 | 3 | Code 4 | nc_unpivot <- pivot_wider(nc_pivoted, values_from = c(births, geometry), 5 | names_from = "year") 6 | Message 7 | ! Ommiting "geometry" column from `values_from` argument. 8 | 9 | # Remove geometry from names 10 | 11 | Code 12 | nc_unpivot <- pivot_wider(nc_pivoted, values_from = births, names_from = c( 13 | geometry, year)) 14 | Message 15 | ! Ommiting "geometry" column from `names_from` argument. 16 | 17 | # error when overwriting existing column 18 | 19 | Code 20 | out <- pivot_wider(df, names_from = key, values_from = val, names_repair = "unique") 21 | Message 22 | New names: 23 | * `a` -> `a...2` 24 | * `a` -> `a...3` 25 | 26 | # `names_from` must be supplied if `name` isn't in `data` (#1240) 27 | 28 | Code 29 | (expect_error(pivot_wider(df, values_from = val))) 30 | Output 31 | 32 | Error in `pivot_wider()`: 33 | ! Can't select columns that don't exist. 34 | x Column `name` doesn't exist. 35 | 36 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/pull_crs.md: -------------------------------------------------------------------------------- 1 | # Check crs 2 | 3 | Code 4 | res <- pull_crs(list(1)) 5 | Message 6 | ! On `tidyterra::pull_crs()` 7 | No wkt equivalent found. Returning NA 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/rowwise-SpatVector-terra.md: -------------------------------------------------------------------------------- 1 | # Gives meaningful messages 2 | 3 | Code 4 | gr_v2 <- gr_v2 %>% mutate(a = 1) 5 | Message 6 | ! `tidyterra::group_vars.SpatVector()` missing on data. Have you mixed terra and tidyterra syntax? 7 | i Ungrouping data 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/rowwise-SpatVector.md: -------------------------------------------------------------------------------- 1 | # Error handling 2 | 3 | Code 4 | rowwise(gr, y) 5 | Condition 6 | Error in `dplyr::rowwise()`: 7 | ! Can't re-group when creating rowwise data. 8 | i Either first `ungroup()` or call `rowwise()` without arguments. 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/scales_col_terrain.md: -------------------------------------------------------------------------------- 1 | # Discrete scale 2 | 3 | Code 4 | p + scale_colour_terrain_d(alpha = -1) 5 | Condition 6 | Error in `scale_colour_terrain_d()`: 7 | ! `alpha` -1 not in [0,1] 8 | 9 | --- 10 | 11 | Code 12 | p + scale_colour_terrain_d(direction = 0.5) 13 | Condition 14 | Error in `scale_colour_terrain_d()`: 15 | ! `direction` must be 1 or -1 16 | 17 | # Continous scale 18 | 19 | Code 20 | p + scale_colour_terrain_c(alpha = -1) 21 | Condition 22 | Error in `scale_colour_terrain_c()`: 23 | ! `alpha` -1 not in [0,1] 24 | 25 | --- 26 | 27 | Code 28 | p + scale_colour_terrain_c(direction = 0.5) 29 | Condition 30 | Error in `scale_colour_terrain_c()`: 31 | ! `direction` must be 1 or -1 32 | 33 | # Breaking scale 34 | 35 | Code 36 | p_init + scale_colour_terrain_b(alpha = -1) 37 | Condition 38 | Error in `scale_colour_terrain_b()`: 39 | ! `alpha` -1 not in [0,1] 40 | 41 | --- 42 | 43 | Code 44 | p + scale_colour_terrain_b(direction = 0.5) 45 | Condition 46 | Error in `scale_colour_terrain_b()`: 47 | ! `direction` must be 1 or -1 48 | 49 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/scales_col_whitebox.md: -------------------------------------------------------------------------------- 1 | # Discrete scale 2 | 3 | Code 4 | p + scale_colour_whitebox_d(alpha = -1) 5 | Condition 6 | Error in `scale_colour_whitebox_d()`: 7 | ! `alpha` -1 not in [0,1] 8 | 9 | --- 10 | 11 | Code 12 | p + scale_colour_whitebox_d(direction = 0.5) 13 | Condition 14 | Error in `scale_colour_whitebox_d()`: 15 | ! `direction` must be 1 or -1 16 | 17 | # Continous scale 18 | 19 | Code 20 | p + scale_colour_whitebox_c(alpha = -1) 21 | Condition 22 | Error in `scale_colour_whitebox_c()`: 23 | ! `alpha` -1 not in [0,1] 24 | 25 | --- 26 | 27 | Code 28 | p + scale_colour_whitebox_c(direction = 0.5) 29 | Condition 30 | Error in `scale_colour_whitebox_c()`: 31 | ! `direction` must be 1 or -1 32 | 33 | # Breaking scale 34 | 35 | Code 36 | p_init + scale_colour_whitebox_b(alpha = -1) 37 | Condition 38 | Error in `scale_colour_whitebox_b()`: 39 | ! `alpha` -1 not in [0,1] 40 | 41 | --- 42 | 43 | Code 44 | p + scale_colour_whitebox_b(direction = 0.5) 45 | Condition 46 | Error in `scale_colour_whitebox_b()`: 47 | ! `direction` must be 1 or -1 48 | 49 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/scales_col_wiki.md: -------------------------------------------------------------------------------- 1 | # Discrete scale 2 | 3 | Code 4 | p + scale_colour_wiki_d(alpha = -1) 5 | Condition 6 | Error in `scale_colour_wiki_d()`: 7 | ! `alpha` -1 not in [0,1] 8 | 9 | --- 10 | 11 | Code 12 | p + scale_colour_wiki_d(direction = 0.5) 13 | Condition 14 | Error in `scale_colour_wiki_d()`: 15 | ! `direction` must be 1 or -1 16 | 17 | # Continous scale 18 | 19 | Code 20 | p + scale_colour_wiki_c(alpha = -1) 21 | Condition 22 | Error in `scale_colour_wiki_c()`: 23 | ! `alpha` -1 not in [0,1] 24 | 25 | --- 26 | 27 | Code 28 | p + scale_colour_wiki_c(direction = 0.5) 29 | Condition 30 | Error in `scale_colour_wiki_c()`: 31 | ! `direction` must be 1 or -1 32 | 33 | # Breaking scale 34 | 35 | Code 36 | p_init + scale_colour_wiki_b(alpha = -1) 37 | Condition 38 | Error in `scale_colour_wiki_b()`: 39 | ! `alpha` -1 not in [0,1] 40 | 41 | --- 42 | 43 | Code 44 | p + scale_colour_wiki_b(direction = 0.5) 45 | Condition 46 | Error in `scale_colour_wiki_b()`: 47 | ! `direction` must be 1 or -1 48 | 49 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/scales_coltab.md: -------------------------------------------------------------------------------- 1 | # Return NULL 2 | 3 | Code 4 | res <- get_coltab_pal(df) 5 | Message 6 | i `tidyterra::get_coltab_pal()` only works with objects, not . Returning NULL 7 | 8 | --- 9 | 10 | Code 11 | res <- get_coltab_pal(r) 12 | Message 13 | i `x` does not have a color table. Returning NULL 14 | 15 | # Give informative messages 16 | 17 | Code 18 | res <- get_coltab_pal(df) 19 | Message 20 | i `tidyterra::get_coltab_pal()` only works with objects, not . Returning NULL 21 | 22 | --- 23 | 24 | Code 25 | res <- get_coltab_pal(r) 26 | Message 27 | i `x` does not have a color table. Returning NULL 28 | 29 | # Discrete scale color 30 | 31 | Code 32 | pnull <- p + scale_color_coltab(data = terra::rast()) 33 | Message 34 | i `x` does not have a color table. Returning NULL 35 | 36 | --- 37 | 38 | Code 39 | p + scale_color_coltab(data = r, alpha = -1) 40 | Condition 41 | Error in `scale_color_coltab()`: 42 | ! `alpha` -1 not in [0,1] 43 | 44 | # Discrete scale fill 45 | 46 | Code 47 | pnull <- p + scale_fill_coltab(data = terra::rast()) 48 | Message 49 | i `x` does not have a color table. Returning NULL 50 | 51 | --- 52 | 53 | Code 54 | p + scale_fill_coltab(data = r, alpha = -1) 55 | Condition 56 | Error in `scale_fill_coltab()`: 57 | ! `alpha` -1 not in [0,1] 58 | 59 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/scales_fill_terrain.md: -------------------------------------------------------------------------------- 1 | # Discrete scale 2 | 3 | Code 4 | p + scale_fill_terrain_d(alpha = -1) 5 | Condition 6 | Error in `scale_fill_terrain_d()`: 7 | ! `alpha` -1 not in [0,1] 8 | 9 | --- 10 | 11 | Code 12 | p + scale_fill_terrain_d(direction = 0.5) 13 | Condition 14 | Error in `scale_fill_terrain_d()`: 15 | ! `direction` must be 1 or -1 16 | 17 | # Continous scale 18 | 19 | Code 20 | p + scale_fill_terrain_c(alpha = -1) 21 | Condition 22 | Error in `scale_fill_terrain_c()`: 23 | ! `alpha` -1 not in [0,1] 24 | 25 | --- 26 | 27 | Code 28 | p + scale_fill_terrain_c(direction = 0.5) 29 | Condition 30 | Error in `scale_fill_terrain_c()`: 31 | ! `direction` must be 1 or -1 32 | 33 | # Breaking scale 34 | 35 | Code 36 | p_init + scale_fill_terrain_b(alpha = -1) 37 | Condition 38 | Error in `scale_fill_terrain_b()`: 39 | ! `alpha` -1 not in [0,1] 40 | 41 | --- 42 | 43 | Code 44 | p + scale_fill_terrain_b(direction = 0.5) 45 | Condition 46 | Error in `scale_fill_terrain_b()`: 47 | ! `direction` must be 1 or -1 48 | 49 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/scales_fill_whitebox.md: -------------------------------------------------------------------------------- 1 | # Discrete scale 2 | 3 | Code 4 | p + scale_fill_whitebox_d(alpha = -1) 5 | Condition 6 | Error in `scale_fill_whitebox_d()`: 7 | ! `alpha` -1 not in [0,1] 8 | 9 | --- 10 | 11 | Code 12 | p + scale_fill_whitebox_d(direction = 0.5) 13 | Condition 14 | Error in `scale_fill_whitebox_d()`: 15 | ! `direction` must be 1 or -1 16 | 17 | # Continous scale 18 | 19 | Code 20 | p + scale_fill_whitebox_c(alpha = -1) 21 | Condition 22 | Error in `scale_fill_whitebox_c()`: 23 | ! `alpha` -1 not in [0,1] 24 | 25 | --- 26 | 27 | Code 28 | p + scale_fill_whitebox_c(direction = 0.5) 29 | Condition 30 | Error in `scale_fill_whitebox_c()`: 31 | ! `direction` must be 1 or -1 32 | 33 | # Breaking scale 34 | 35 | Code 36 | p_init + scale_fill_whitebox_b(alpha = -1) 37 | Condition 38 | Error in `scale_fill_whitebox_b()`: 39 | ! `alpha` -1 not in [0,1] 40 | 41 | --- 42 | 43 | Code 44 | p + scale_fill_whitebox_b(direction = 0.5) 45 | Condition 46 | Error in `scale_fill_whitebox_b()`: 47 | ! `direction` must be 1 or -1 48 | 49 | # Palette 50 | 51 | Code 52 | whitebox.colors(20, "xx") 53 | Condition 54 | Error in `extract_pal()`: 55 | ! `palette` does not match any given palette 56 | 57 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/scales_fill_wiki.md: -------------------------------------------------------------------------------- 1 | # Discrete scale 2 | 3 | Code 4 | p + scale_fill_wiki_d(alpha = -1) 5 | Condition 6 | Error in `scale_fill_wiki_d()`: 7 | ! `alpha` -1 not in [0,1] 8 | 9 | --- 10 | 11 | Code 12 | p + scale_fill_wiki_d(direction = 0.5) 13 | Condition 14 | Error in `scale_fill_wiki_d()`: 15 | ! `direction` must be 1 or -1 16 | 17 | # Continous scale 18 | 19 | Code 20 | p + scale_fill_wiki_c(alpha = -1) 21 | Condition 22 | Error in `scale_fill_wiki_c()`: 23 | ! `alpha` -1 not in [0,1] 24 | 25 | --- 26 | 27 | Code 28 | p + scale_fill_wiki_c(direction = 0.5) 29 | Condition 30 | Error in `scale_fill_wiki_c()`: 31 | ! `direction` must be 1 or -1 32 | 33 | # Breaking scale 34 | 35 | Code 36 | p_init + scale_fill_wiki_b(alpha = -1) 37 | Condition 38 | Error in `scale_fill_wiki_b()`: 39 | ! `alpha` -1 not in [0,1] 40 | 41 | --- 42 | 43 | Code 44 | p + scale_fill_wiki_b(direction = 0.5) 45 | Condition 46 | Error in `scale_fill_wiki_b()`: 47 | ! `direction` must be 1 or -1 48 | 49 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/select-Spat.md: -------------------------------------------------------------------------------- 1 | # grouping variables preserved with a msg, unless already selected 2 | 3 | Code 4 | res <- select(df, x) 5 | Message 6 | Adding missing grouping variables: `g` 7 | 8 | --- 9 | 10 | Code 11 | expect_equal(df %>% select(a = c) %>% group_keys(), tibble::tibble(b = 2, a = 3) %>% 12 | group_by(b) %>% group_keys()) 13 | Message 14 | Adding missing grouping variables: `b` 15 | Code 16 | expect_equal(df %>% select(b = c) %>% group_keys(), tibble::tibble(a = 1, b = 3) %>% 17 | group_by(a) %>% group_keys()) 18 | Message 19 | Adding missing grouping variables: `a` 20 | 21 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/stat_spatraster.md: -------------------------------------------------------------------------------- 1 | # Minimal checks for stat_spatraster 1lyr CRS 2 | 3 | Code 4 | ggplot() + stat_spatraster(data = v) 5 | Condition 6 | Error in `stat_spatraster()`: 7 | ! `tidyterra::stat_spatraster()` only works with objects, not . See `?terra::vect()` 8 | 9 | --- 10 | 11 | Code 12 | ggplot() + stat_spatraster(data = 1:3) 13 | Condition 14 | Error in `stat_spatraster()`: 15 | ! `tidyterra::stat_spatraster()` only works with objects, not . See `?terra::vect()` 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/test-as_coordinates.R: -------------------------------------------------------------------------------- 1 | test_that("as_coordinates errors", { 2 | skip_on_cran() 3 | v <- volcano 4 | expect_snapshot(as_coordinates(v), error = TRUE) 5 | }) 6 | 7 | test_that("as_coordinates return a skeleton", { 8 | skip_on_cran() 9 | v <- volcano 10 | 11 | r <- terra::rast(t(v)) 12 | 13 | df <- as_coordinates(r) 14 | 15 | expect_s3_class(df, "tbl") 16 | expect_true(all(names(df) == c( 17 | "cellindex", 18 | "rowindex", 19 | "colindex" 20 | ))) 21 | 22 | expect_true(nrow(df) == terra::ncell(r)) 23 | expect_true(ncol(df) == 3) 24 | 25 | expect_equal( 26 | unique(sort(df$rowindex)), 27 | seq_len(terra::nrow(r)) 28 | ) 29 | 30 | expect_equal( 31 | unique(sort(df$colindex)), 32 | seq_len(terra::ncol(r)) 33 | ) 34 | 35 | expect_equal( 36 | df$cellindex, 37 | seq_len(terra::ncell(r)) 38 | ) 39 | }) 40 | 41 | 42 | test_that("as_coordinates return a raster", { 43 | skip_on_cran() 44 | v <- volcano 45 | r <- terra::rast(t(v)) 46 | 47 | a_rast <- as_coordinates(r, as.raster = TRUE) 48 | 49 | expect_s4_class(a_rast, "SpatRaster") 50 | 51 | expect_true(compare_spatrasters(r, a_rast)) 52 | 53 | # With crs 54 | r_crs <- r 55 | 56 | terra::crs(r_crs) <- pull_crs("EPSG:3857") 57 | 58 | a_rast_crs <- as_coordinates(r_crs, as.raster = TRUE) 59 | 60 | expect_s4_class(a_rast_crs, "SpatRaster") 61 | expect_true(compare_spatrasters(r_crs, a_rast_crs)) 62 | }) 63 | -------------------------------------------------------------------------------- /tests/testthat/test-compare_spatrasters.R: -------------------------------------------------------------------------------- 1 | test_that("Error", { 2 | skip_on_cran() 3 | 4 | x <- terra::rast(matrix(1:90, ncol = 3), crs = "EPSG:3857") 5 | 6 | # Compare with other types 7 | expect_snapshot(compare_spatrasters(x, terra::crs(x)), error = TRUE) 8 | expect_snapshot(compare_spatrasters(1, "a"), error = TRUE) 9 | }) 10 | 11 | 12 | test_that("Equal", { 13 | skip_on_cran() 14 | 15 | x <- terra::rast(matrix(1:90, ncol = 3), crs = "EPSG:3857") 16 | 17 | expect_silent(compare_spatrasters(x, x)) 18 | expect_true(compare_spatrasters(x, x)) 19 | }) 20 | 21 | 22 | test_that("Different crs", { 23 | skip_on_cran() 24 | 25 | x <- terra::rast(matrix(1:90, ncol = 3), crs = "EPSG:3857") 26 | y <- x 27 | 28 | terra::crs(y) <- NA 29 | expect_snapshot(res <- compare_spatrasters(x, y)) 30 | expect_false(res) 31 | }) 32 | 33 | 34 | test_that("Different extent", { 35 | skip_on_cran() 36 | 37 | x <- terra::rast(matrix(1:90, ncol = 3), crs = "EPSG:3857") 38 | y <- x[1:5, , drop = FALSE] 39 | 40 | 41 | expect_snapshot(res <- compare_spatrasters(x, y)) 42 | expect_false(res) 43 | }) 44 | 45 | 46 | test_that("Different resolution", { 47 | skip_on_cran() 48 | 49 | x <- terra::rast(matrix(1:90, ncol = 3), crs = "EPSG:3857") 50 | y <- x 51 | 52 | terra::res(y) <- terra::res(x) / 2 53 | 54 | expect_snapshot(res <- compare_spatrasters(x, y)) 55 | expect_false(res) 56 | }) 57 | 58 | 59 | test_that("All different", { 60 | skip_on_cran() 61 | 62 | x <- terra::rast(matrix(1:90, ncol = 3), crs = "EPSG:3857") 63 | y <- terra::project(x, "epsg:3035") 64 | 65 | 66 | expect_snapshot(res <- compare_spatrasters(x, y)) 67 | expect_false(res) 68 | }) 69 | -------------------------------------------------------------------------------- /tests/testthat/test-pull_crs.R: -------------------------------------------------------------------------------- 1 | test_that("Check crs", { 2 | expect_snapshot(res <- pull_crs(list(1))) 3 | expect_true(is.na(res)) 4 | 5 | expect_true(is.na(pull_crs(NA))) 6 | expect_silent(is.na(pull_crs(NA))) 7 | 8 | expect_true(is.na(pull_crs(NULL))) 9 | expect_silent(is.na(pull_crs(NULL))) 10 | 11 | expect_true(is.na(pull_crs(""))) 12 | expect_silent(is.na(pull_crs(""))) 13 | 14 | expect_error(pull_crs("Some string")) 15 | skip_on_cran() 16 | 17 | # Base for comparison 18 | base <- pull_crs(4326) 19 | 20 | sfobj <- sf::st_as_sfc("MULTIPOINT ((0 0), (1 1))", crs = 4326) 21 | 22 | expect_s3_class(sfobj, "sfc") 23 | sfc <- pull_crs(sfobj) 24 | 25 | sfobj2 <- sf::st_sf(sfobj) 26 | 27 | expect_s3_class(sfobj2, "sf") 28 | sf2 <- pull_crs(sfobj2) 29 | 30 | # On sf with columns with NA also works 31 | sf_na <- sfobj2 32 | 33 | sf_na$no_na <- "A" 34 | sf_na$no_na <- NA 35 | 36 | expect_true(any(is.na(sf_na))) 37 | expect_s3_class(sf_na, "sf") 38 | sf_na_check <- pull_crs(sf_na) 39 | 40 | crs <- sf::st_crs(sfobj) 41 | 42 | expect_s3_class(crs, "crs") 43 | crs2 <- pull_crs(crs) 44 | 45 | # terra 46 | 47 | v <- terra::vect(sfobj2) 48 | 49 | expect_s4_class(v, "SpatVector") 50 | v2 <- pull_crs(v) 51 | 52 | r <- terra::rast(v) 53 | 54 | expect_s4_class(r, "SpatRaster") 55 | r2 <- pull_crs(r) 56 | 57 | # Characters 58 | fromchar <- pull_crs("epsg:4326") 59 | 60 | expect_true(all.equal( 61 | base, 62 | sfc, 63 | sf2, 64 | sf_na_check, 65 | crs2, 66 | r2, 67 | v2, 68 | fromchar 69 | )) 70 | }) 71 | -------------------------------------------------------------------------------- /tests/testthat/test-relocate-Spat.R: -------------------------------------------------------------------------------- 1 | test_that("SpatRaster", { 2 | skip_on_cran() 3 | f <- system.file("extdata/cyl_temp.tif", package = "tidyterra") 4 | spatrast <- terra::rast(f) 5 | 6 | mod <- spatrast %>% 7 | mutate(exp_lyr1 = exp(tavg_04 / 10)) %>% 8 | relocate(exp_lyr1, .before = 1) 9 | 10 | expect_true(all(names(mod) == c("exp_lyr1", names(spatrast)))) 11 | 12 | expect_true(compare_spatrasters(spatrast, mod)) 13 | 14 | mod2 <- mod %>% relocate(tavg_05, .after = dplyr::last_col()) 15 | 16 | expect_true(compare_spatrasters(spatrast, mod2)) 17 | 18 | col_pos <- which(names(mod) == "tavg_05") 19 | 20 | expect_true( 21 | all(c(names(mod2)[-col_pos], names(mod2)[col_pos]) == names(mod)) 22 | ) 23 | }) 24 | 25 | 26 | test_that("SpatVector", { 27 | skip_on_cran() 28 | # SpatVector method 29 | f <- system.file("extdata/cyl.gpkg", package = "tidyterra") 30 | v <- terra::vect(f) 31 | 32 | mod <- v %>% 33 | mutate(exp_attr = "a") %>% 34 | relocate(exp_attr, .before = 1) 35 | 36 | expect_s4_class(mod, "SpatVector") 37 | 38 | expect_true(all(names(mod) == c("exp_attr", names(v)))) 39 | 40 | 41 | mod2 <- mod %>% relocate(cpro, .after = dplyr::last_col()) 42 | 43 | expect_s4_class(mod2, "SpatVector") 44 | 45 | col_pos <- which(names(mod) == "cpro") 46 | 47 | expect_true( 48 | all(c(names(mod2)[-col_pos], names(mod2)[col_pos]) == names(mod)) 49 | ) 50 | }) 51 | -------------------------------------------------------------------------------- /tests/testthat/test-transmute-Spat.R: -------------------------------------------------------------------------------- 1 | test_that("SpatRaster transmute", { 2 | skip_on_cran() 3 | f <- system.file("extdata/cyl_temp.tif", package = "tidyterra") 4 | spatrast <- terra::rast(f) 5 | 6 | mod <- spatrast %>% 7 | transmute(exp_lyr1 = exp(tavg_04 / 10)) 8 | 9 | expect_true(compare_spatrasters(spatrast, mod)) 10 | expect_equal(terra::nlyr(mod), 1) 11 | }) 12 | 13 | test_that("SpatVector", { 14 | skip_on_cran() 15 | # SpatVector method 16 | f <- system.file("extdata/cyl.gpkg", package = "tidyterra") 17 | v <- terra::vect(f) 18 | 19 | mutated <- v %>% 20 | transmute(cpro2 = paste0(cpro, "-CyL")) 21 | 22 | expect_s4_class(mutated, "SpatVector") 23 | expect_equal(ncol(mutated), 1) 24 | expect_identical( 25 | mutated$cpro2, 26 | paste0(v$cpro, "-CyL") 27 | ) 28 | }) 29 | 30 | test_that("transmute preserves grouping", { 31 | skip_on_cran() 32 | df <- tibble::tibble(x = 1:2, y = 2) 33 | df <- as_spatvector(df, geom = c("x", "y"), keepgeom = TRUE) 34 | gf <- group_by(df, x) 35 | 36 | out <- transmute(gf, x = 1) 37 | 38 | expect_equal(group_vars(out), "x") 39 | expect_equal(nrow(group_data(out)), 1) 40 | 41 | out <- transmute(gf, z = 1) 42 | 43 | expect_equal(group_data(out), group_data(gf)) 44 | }) 45 | 46 | # Empty transmutes ------------------------------------------------- 47 | 48 | test_that("transmute with no args returns grouping vars", { 49 | skip_on_cran() 50 | df <- tibble::tibble(x = 1, y = 2) 51 | df <- as_spatvector(df, geom = c("x", "y"), keepgeom = TRUE) 52 | 53 | gf <- group_by(df, x) 54 | expect_equal(df %>% transmute() %>% ncol(), 0) 55 | expect_equal(gf %>% transmute() %>% ncol(), 1) 56 | expect_equal(gf %>% transmute() %>% names(), "x") 57 | }) 58 | -------------------------------------------------------------------------------- /tests/testthat/test-utils.R: -------------------------------------------------------------------------------- 1 | test_that("make_safe_index works", { 2 | df <- data.frame(a = 1, b = 1, c = 1) 3 | expect_equal("tterra_index", make_safe_index("tterra_index", df)) 4 | expect_equal("aname", make_safe_index("aname", df)) 5 | expect_equal("a_001", make_safe_index("a", df)) 6 | 7 | names(df) <- c("a_002", "b", "a") 8 | expect_equal("a_001", make_safe_index("a", df)) 9 | 10 | names(df) <- c("a_002", "a", "a_001") 11 | expect_equal("a_003", make_safe_index("a", df)) 12 | }) 13 | 14 | test_that("make_safe_index iterates until make safe name", { 15 | m <- matrix(nrow = 1, ncol = 20) 16 | df <- as.data.frame(m) 17 | 18 | 19 | nnames <- paste0("a_", sprintf("%03d", seq_len(ncol(df)))) 20 | names(df) <- nnames 21 | expect_identical(names(df), nnames) 22 | 23 | # Add a 24 | df_new <- cbind(df, data.frame(a = 1)) 25 | 26 | expect_equal("a_021", make_safe_index("a", df_new)) 27 | }) 28 | -------------------------------------------------------------------------------- /tidyterra.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: f9bbfc7f-498e-4f6d-883f-38dda3810dfd 3 | 4 | RestoreWorkspace: No 5 | SaveWorkspace: No 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | AutoAppendNewline: Yes 17 | StripTrailingWhitespace: Yes 18 | LineEndingConversion: Posix 19 | 20 | BuildType: Package 21 | PackageUseDevtools: Yes 22 | PackageInstallArgs: --no-multiarch --with-keep.source 23 | PackageRoxygenize: rd,collate,namespace 24 | 25 | MarkdownWrap: Column 26 | MarkdownWrapAtColumn: 80 27 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/aggregate-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/aggregate-1.png -------------------------------------------------------------------------------- /vignettes/aggregate-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/aggregate-2.png -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/83d8f6fd655e9e33554068e008a466ff.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/83d8f6fd655e9e33554068e008a466ff.tif -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/83d8f6fd655e9e33554068e008a466ff.tif.aux.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | red 4 | 5 | 255 6 | -9999 7 | 126 8 | -9999 9 | 10 | 11 | 12 | green 13 | 14 | 255 15 | -9999 16 | 140 17 | -9999 18 | 19 | 20 | 21 | blue 22 | 23 | 255 24 | -9999 25 | 134 26 | -9999 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_132_89.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_132_89.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_132_90.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_132_90.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_132_91.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_132_91.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_133_89.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_133_89.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_133_90.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_133_90.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_133_91.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_133_91.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_134_89.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_134_89.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_134_90.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_134_90.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_134_91.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_134_91.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_135_89.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_135_89.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_135_90.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_135_90.jpg -------------------------------------------------------------------------------- /vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_135_91.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/Esri.WorldShadedRelief/Esri.WorldShadedRelief_8_135_91.jpg -------------------------------------------------------------------------------- /vignettes/articles/OpenStreetMap/3ff88f2a659533f469cb56031b4fb4b2.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/OpenStreetMap/3ff88f2a659533f469cb56031b4fb4b2.tif -------------------------------------------------------------------------------- /vignettes/articles/OpenStreetMap/3ff88f2a659533f469cb56031b4fb4b2.tif.aux.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | red 4 | 5 | 254 6 | -9999 7 | 13 8 | -9999 9 | 10 | 11 | 12 | green 13 | 14 | 254 15 | -9999 16 | 63 17 | -9999 18 | 19 | 20 | 21 | blue 22 | 23 | 254 24 | -9999 25 | 22 26 | -9999 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /vignettes/articles/OpenStreetMap/9f654eb084cc35bf3b45121bab5cc4ba.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/OpenStreetMap/9f654eb084cc35bf3b45121bab5cc4ba.tif -------------------------------------------------------------------------------- /vignettes/articles/OpenStreetMap/9f654eb084cc35bf3b45121bab5cc4ba.tif.aux.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | red 4 | 5 | 254 6 | -9999 7 | 13 8 | -9999 9 | 10 | 11 | 12 | green 13 | 14 | 254 15 | -9999 16 | 63 17 | -9999 18 | 19 | 20 | 21 | blue 22 | 23 | 254 24 | -9999 25 | 22 26 | -9999 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /vignettes/articles/OpenStreetMap/OpenStreetMap_14_8047_5105.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8047_5105.png -------------------------------------------------------------------------------- /vignettes/articles/OpenStreetMap/OpenStreetMap_14_8047_5106.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8047_5106.png -------------------------------------------------------------------------------- /vignettes/articles/OpenStreetMap/OpenStreetMap_14_8048_5105.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8048_5105.png -------------------------------------------------------------------------------- /vignettes/articles/OpenStreetMap/OpenStreetMap_14_8048_5106.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8048_5106.png -------------------------------------------------------------------------------- /vignettes/articles/che_temp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/che_temp.gif -------------------------------------------------------------------------------- /vignettes/articles/clc_edinburgh.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/clc_edinburgh.tif -------------------------------------------------------------------------------- /vignettes/articles/climate/wc2.1_country/CHE_wc2.1_30s_prec.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/climate/wc2.1_country/CHE_wc2.1_30s_prec.tif -------------------------------------------------------------------------------- /vignettes/articles/climate/wc2.1_country/CHE_wc2.1_30s_tavg.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/climate/wc2.1_country/CHE_wc2.1_30s_tavg.tif -------------------------------------------------------------------------------- /vignettes/articles/gadm/gadm41_CHE_0_pk.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/gadm/gadm41_CHE_0_pk.rds -------------------------------------------------------------------------------- /vignettes/articles/holyroodpark.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/articles/holyroodpark.tif -------------------------------------------------------------------------------- /vignettes/articles/wild.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "tidyterra in the wild" 3 | description: Use of tidyterra in publications. 4 | bibliography: INPUBS.bib 5 | csl: apa.csl 6 | nocite: '@*' 7 | --- 8 | 9 | Please cite **tidyterra** as: 10 | 11 | Hernangómez, D., (2023). Using the tidyverse with terra objects: the tidyterra 12 | package. *Journal of Open Source Software*, *8*(91), 5751, 13 | . 14 | 15 | A BibTeX entry for LaTeX users is: 16 | 17 | ``` bib 18 | @article{Hernangómez2023, 19 | doi = {10.21105/joss.05751}, 20 | url = {https://doi.org/10.21105/joss.05751}, 21 | year = {2023}, 22 | publisher = {The Open Journal}, 23 | volume = {8}, 24 | number = {91}, 25 | pages = {5751}, 26 | author = {Diego Hernangómez}, 27 | title = {Using the {tidyverse} with {terra} objects: the {tidyterra} package}, 28 | journal = {Journal of Open Source Software} 29 | } 30 | ``` 31 | 32 |

33 | 34 | ## Publications 35 | -------------------------------------------------------------------------------- /vignettes/contourfilled-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/contourfilled-1.png -------------------------------------------------------------------------------- /vignettes/contourlines-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/contourlines-1.png -------------------------------------------------------------------------------- /vignettes/faceted-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/faceted-1.png -------------------------------------------------------------------------------- /vignettes/hypso-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/hypso-1.png -------------------------------------------------------------------------------- /vignettes/lux_ggplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/lux_ggplot-1.png -------------------------------------------------------------------------------- /vignettes/rgb-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/rgb-1.png -------------------------------------------------------------------------------- /vignettes/spatraster-example1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/spatraster-example1-1.png -------------------------------------------------------------------------------- /vignettes/spatraster-example2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dieghernan/tidyterra/ad7801b9d66149d325535921586c62bd31cf1ad5/vignettes/spatraster-example2-1.png --------------------------------------------------------------------------------