diff --git a/codemeta.json b/codemeta.json
index 87a2b119..d0150d01 100644
--- a/codemeta.json
+++ b/codemeta.json
@@ -344,7 +344,7 @@
"SystemRequirements": null
},
"keywords": ["r", "terra", "ggplot-extension", "r-spatial", "rspatial", "r-package", "rstats", "rstats-package", "cran", "cran-r"],
- "fileSize": "2289.35KB",
+ "fileSize": "2289.359KB",
"citation": [
{
"@type": "ScholarlyArticle",
diff --git a/data-raw/dems/.gitignore b/data-raw/dems/.gitignore
new file mode 100644
index 00000000..8ac148d5
--- /dev/null
+++ b/data-raw/dems/.gitignore
@@ -0,0 +1 @@
+NT27SE_50CM_DSM_PHASE5.tif
diff --git a/data-raw/holyroodpark.R b/data-raw/holyroodpark.R
new file mode 100644
index 00000000..df4aa15d
--- /dev/null
+++ b/data-raw/holyroodpark.R
@@ -0,0 +1,38 @@
+## code to prepare `holyroodpark` dataset goes here
+
+# Data from https://remotesensingdata.gov.scot/
+# Scotland Lidar Phase 5 DSM NT27SE
+# License: https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/
+
+
+library(terra)
+r <- rast("data-raw/dems/NT27SE_50CM_DSM_PHASE5.tif")
+
+# Cut to fit Holyrood Park
+hopark <- rast()
+
+ext(hopark) <- c(-3.178208, -3.142817, 55.939184, 55.95418)
+
+hopark <- project(hopark, terra::crs(r))
+res(hopark) <- c(2.5, 2.5)
+
+final_rast <- terra::project(r, hopark)
+ncell(final_rast)
+names(final_rast) <- "elevation"
+plot(final_rast)
+# Extra clip
+xa <- 1000
+xb <- 200
+ya <- 300
+yb <- 300
+f2 <- as.vector(ext(final_rast))
+f2_x <- f2 - c(xa, xb, ya, yb)
+
+xtraclip <- crop(final_rast, ext(f2_x))
+plot(xtraclip)
+ncell(xtraclip)
+
+unlink("data-raw/holyroodpark.tif")
+unlink("vignettes/articles/holyroodpark.tif")
+writeRaster(final_rast, "data-raw/holyroodpark.tif")
+writeRaster(final_rast, "vignettes/articles/holyroodpark.tif")
diff --git a/data-raw/holyroodpark.tif b/data-raw/holyroodpark.tif
new file mode 100644
index 00000000..78f37af6
Binary files /dev/null and b/data-raw/holyroodpark.tif differ
diff --git a/inst/WORDLIST b/inst/WORDLIST
index 49398560..c401734a 100644
--- a/inst/WORDLIST
+++ b/inst/WORDLIST
@@ -6,12 +6,15 @@ CodeFactor
Colorimetric
Coords
DOI
+DSM
EPSG
Hijmans
+Holyrood
Hypsometric
ISSN
JOSS
LiDAR
+Licence
Maungawhau
NZGD
ORCID
@@ -45,7 +48,6 @@ coord
cpt
crs
de
-dev
disaggregated
doi
downsampled
diff --git a/vignettes/articles/OpenStreetMap/3ff88f2a659533f469cb56031b4fb4b2.tif b/vignettes/articles/OpenStreetMap/3ff88f2a659533f469cb56031b4fb4b2.tif
new file mode 100644
index 00000000..93056dd3
Binary files /dev/null and b/vignettes/articles/OpenStreetMap/3ff88f2a659533f469cb56031b4fb4b2.tif differ
diff --git a/vignettes/articles/OpenStreetMap/f3163ae294202a708cc764ee77b4c828.tif.aux.xml b/vignettes/articles/OpenStreetMap/3ff88f2a659533f469cb56031b4fb4b2.tif.aux.xml
similarity index 70%
rename from vignettes/articles/OpenStreetMap/f3163ae294202a708cc764ee77b4c828.tif.aux.xml
rename to vignettes/articles/OpenStreetMap/3ff88f2a659533f469cb56031b4fb4b2.tif.aux.xml
index 9908832a..2dd7ab0e 100644
--- a/vignettes/articles/OpenStreetMap/f3163ae294202a708cc764ee77b4c828.tif.aux.xml
+++ b/vignettes/articles/OpenStreetMap/3ff88f2a659533f469cb56031b4fb4b2.tif.aux.xml
@@ -2,27 +2,27 @@
red
- 255
+ 254
-9999
- 7
+ 13
-9999
green
- 255
+ 254
-9999
- 7
+ 63
-9999
blue
- 255
+ 254
-9999
- 6
+ 22
-9999
diff --git a/vignettes/articles/OpenStreetMap/9f654eb084cc35bf3b45121bab5cc4ba.tif b/vignettes/articles/OpenStreetMap/9f654eb084cc35bf3b45121bab5cc4ba.tif
new file mode 100644
index 00000000..95e216bb
Binary files /dev/null and b/vignettes/articles/OpenStreetMap/9f654eb084cc35bf3b45121bab5cc4ba.tif differ
diff --git a/vignettes/articles/OpenStreetMap/b476e80163f3d56debe74eb23a2db84d.tif.aux.xml b/vignettes/articles/OpenStreetMap/9f654eb084cc35bf3b45121bab5cc4ba.tif.aux.xml
similarity index 70%
rename from vignettes/articles/OpenStreetMap/b476e80163f3d56debe74eb23a2db84d.tif.aux.xml
rename to vignettes/articles/OpenStreetMap/9f654eb084cc35bf3b45121bab5cc4ba.tif.aux.xml
index aba00a7a..2dd7ab0e 100644
--- a/vignettes/articles/OpenStreetMap/b476e80163f3d56debe74eb23a2db84d.tif.aux.xml
+++ b/vignettes/articles/OpenStreetMap/9f654eb084cc35bf3b45121bab5cc4ba.tif.aux.xml
@@ -2,27 +2,27 @@
red
- 255
+ 254
-9999
- 18
+ 13
-9999
green
- 255
+ 254
-9999
- 18
+ 63
-9999
blue
- 255
+ 254
-9999
- 7
+ 22
-9999
diff --git a/vignettes/articles/OpenStreetMap/OpenStreetMap_14_3772_6678.png b/vignettes/articles/OpenStreetMap/OpenStreetMap_14_3772_6678.png
deleted file mode 100644
index 3d5a39bd..00000000
Binary files a/vignettes/articles/OpenStreetMap/OpenStreetMap_14_3772_6678.png and /dev/null differ
diff --git a/vignettes/articles/OpenStreetMap/OpenStreetMap_14_3773_6678.png b/vignettes/articles/OpenStreetMap/OpenStreetMap_14_3773_6678.png
deleted file mode 100644
index b75e6bc9..00000000
Binary files a/vignettes/articles/OpenStreetMap/OpenStreetMap_14_3773_6678.png and /dev/null differ
diff --git a/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8047_5105.png b/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8047_5105.png
new file mode 100644
index 00000000..9e7df21c
Binary files /dev/null and b/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8047_5105.png differ
diff --git a/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8047_5106.png b/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8047_5106.png
new file mode 100644
index 00000000..745269f9
Binary files /dev/null and b/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8047_5106.png differ
diff --git a/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8048_5105.png b/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8048_5105.png
new file mode 100644
index 00000000..c2f46230
Binary files /dev/null and b/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8048_5105.png differ
diff --git a/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8048_5106.png b/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8048_5106.png
new file mode 100644
index 00000000..89b77e58
Binary files /dev/null and b/vignettes/articles/OpenStreetMap/OpenStreetMap_14_8048_5106.png differ
diff --git a/vignettes/articles/OpenStreetMap/b476e80163f3d56debe74eb23a2db84d.tif b/vignettes/articles/OpenStreetMap/b476e80163f3d56debe74eb23a2db84d.tif
deleted file mode 100644
index bbe16b39..00000000
Binary files a/vignettes/articles/OpenStreetMap/b476e80163f3d56debe74eb23a2db84d.tif and /dev/null differ
diff --git a/vignettes/articles/OpenStreetMap/f3163ae294202a708cc764ee77b4c828.tif b/vignettes/articles/OpenStreetMap/f3163ae294202a708cc764ee77b4c828.tif
deleted file mode 100644
index eed14b44..00000000
Binary files a/vignettes/articles/OpenStreetMap/f3163ae294202a708cc764ee77b4c828.tif and /dev/null differ
diff --git a/vignettes/articles/faqs.Rmd b/vignettes/articles/faqs.Rmd
index ca19dc77..c39e5269 100644
--- a/vignettes/articles/faqs.Rmd
+++ b/vignettes/articles/faqs.Rmd
@@ -30,14 +30,39 @@ You can also ask in [Stack Overflow](https://stackoverflow.com/) using the tag
- Ask a question
[[link](https://github.com/dieghernan/tidyterra/discussions)].
+### Example data
+
+#### Source
+
+This article uses a sample of **LiDAR for Scotland Phase 5 - DSM** provided by
+[The Scottish Remote Sensing Portal](https://remotesensingdata.gov.scot/). This
+data is made available under the [Open Government Licence
+v3](http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/).
+
+#### About the file
+
+The file `holyroodpark.tif` represents the DEM[^1] of [Holyrood Park, Edinburgh
+(Scotland)](https://en.wikipedia.org/wiki/Holyrood_Park), including [Arthur's
+Seat](https://en.wikipedia.org/wiki/Arthur%27s_Seat), an extinct volcano, pretty
+much as the famous [Maungawhau / Mount
+Eden](https://en.wikipedia.org/wiki/Maungawhau_/_Mount_Eden) volcano represented
+in `datasets::volcano`.
+
+[^1]: Digital Elevation Model, representing the elevation of the corresponding
+ area.
+
+The original file has been cropped and down-sampled for demo purposes,
+`holyroodpark.tif` is available online in
+ folder.
+
## `NA` values are shown in gray color {#nas-remove}
This is the default behavior produced by the **ggplot2** package. **tidyterra**
color scales (i.e., `scale_fill_whitebox_c()`, etc.), has by default the
parameter `na.value` set to `"transparent"`, that prevents `NA` values to be
-filled[^1].
+filled[^2].
-[^1]: `na.value = NA` could be used as well for the same purpose in most of the
+[^2]: `na.value = NA` could be used as well for the same purpose in most of the
cases, however when the proportion of non-`NA`s is small it can produce
undesired results, see
[#120](https://github.com/dieghernan/tidyterra/issues/120).
@@ -47,19 +72,10 @@ library(terra)
library(tidyterra)
library(ggplot2)
-# Get a raster data, out beloved volcano on hi-res
-volcanotemp <- "volcano2hires.tif"
+# Get a raster data from Holyrood Park, Edinburgh
+holyrood <- "holyroodpark.tif"
-# Download example file
-volcanourl <- paste0(
- "https://github.com/dieghernan/tidyterra/blob/main/",
- "data-raw/volcano2hires.tif?raw=true"
-)
-
-if (!file.exists(volcanotemp)) {
- download.file(volcanourl, volcanotemp, mode = "wb")
-}
-r <- volcanotemp %>%
+r <- holyrood %>%
rast() %>%
filter(elevation > 80 & elevation < 180)
@@ -100,20 +116,9 @@ library(terra)
library(tidyterra)
library(ggplot2)
-volcanotemp <- "volcano2hires.tif"
+holyrood <- "holyroodpark.tif"
-# Download example file
-volcanourl <- paste0(
- "https://github.com/dieghernan/tidyterra/blob/main/",
- "data-raw/volcano2hires.tif?raw=true"
-)
-
-if (!file.exists(volcanotemp)) {
- download.file(volcanourl, volcanotemp, mode = "wb")
-}
-
-
-r <- rast(volcanotemp)
+r <- rast(holyrood)
ggplot() +
geom_spatraster_contour_text(data = r) +
@@ -133,7 +138,7 @@ labeller <- function(labs) {
# Common labels across ggplot
-labs <- c(100, 140, 180)
+labs <- c(100, 140, 180, 220)
ggplot(r) +
geom_spatraster_contour_text(
@@ -142,7 +147,7 @@ ggplot(r) +
size = after_stat(level),
color = after_stat(level)
),
- breaks = seq(80, 200, 10),
+ breaks = seq(100, 250, 10),
# Just label some isolines
label_format = labeller(labs = labs),
family = "mono",
@@ -169,13 +174,13 @@ ggplot(r) +
### Other alternatives
Thanks to `fortify.SpatRaster()` you can use your `SpatRaster` straight away
-with the **metR** package (see [Hexagonal grids and other geoms](#fort)).
-Use the parameter(s) `bins/binwidth/breaks` to align both labels and lines:
+with the **metR** package (see [Hexagonal grids and other geoms](#fort)). Use
+the parameter(s) `bins/binwidth/breaks` to align both labels and lines:
```{r metr}
library(metR)
-br <- seq(80, 200, 10)
-labs <- c(100, 140, 180)
+br <- seq(100, 250, 10)
+labs <- c(100, 140, 180, 220)
# Replicate previous map with tidyterra + metR strategy
ggplot(r, aes(x, y)) +
@@ -234,20 +239,9 @@ library(terra)
library(tidyterra)
library(ggplot2)
-volcanotemp <- "volcano2hires.tif"
-
-# Download example file
-volcanourl <- paste0(
- "https://github.com/dieghernan/tidyterra/blob/main/",
- "data-raw/volcano2hires.tif?raw=true"
-)
-
-if (!file.exists(volcanotemp)) {
- download.file(volcanourl, volcanotemp, mode = "wb")
-}
-
+holyrood <- "holyroodpark.tif"
-r <- rast(volcanotemp)
+r <- rast(holyrood)
# Hillshade with grey colors
slope <- terrain(r, "slope", unit = "radians")
@@ -274,20 +268,9 @@ library(terra)
library(tidyterra)
library(ggplot2)
-volcanotemp <- "volcano2hires.tif"
-
-# Download example file
-volcanourl <- paste0(
- "https://github.com/dieghernan/tidyterra/blob/main/",
- "data-raw/volcano2hires.tif?raw=true"
-)
-
-if (!file.exists(volcanotemp)) {
- download.file(volcanourl, volcanotemp, mode = "wb")
-}
-
+holyrood <- "holyroodpark.tif"
-r <- rast(volcanotemp)
+r <- rast(holyrood)
p <- ggplot() +
geom_spatraster(data = r)
@@ -324,16 +307,17 @@ library(sf)
library(maptiles)
# Get a tile from a point on sf format
-
-p <- st_point(c(-97.09, 31.53)) %>%
+p <- st_point(c(-3.166011, 55.945235)) %>%
st_sfc(crs = 4326) %>%
- st_buffer(750)
+ st_buffer(500)
-tile1 <- get_tiles(p, provider = "OpenStreetMap", zoom = 14, cachedir = ".")
+tile1 <- get_tiles(p,
+ provider = "OpenStreetMap", zoom = 14, cachedir = ".",
+ crop = TRUE
+)
ggplot() +
geom_spatraster_rgb(data = tile1) +
- geom_sf(data = p, fill = NA) +
labs(title = "This is a bit blurry...")
st_crs(tile1)$epsg
@@ -344,7 +328,10 @@ st_crs(tile1)$epsg
p2 <- st_transform(p, 3857)
-tile2 <- get_tiles(p2, provider = "OpenStreetMap", zoom = 14, cachedir = ".")
+tile2 <- get_tiles(p2,
+ provider = "OpenStreetMap", zoom = 14, cachedir = ".",
+ crop = TRUE
+)
st_crs(tile2)$epsg
@@ -352,7 +339,6 @@ st_crs(tile2)$epsg
ggplot() +
geom_spatraster_rgb(data = tile2, maxcell = Inf) +
- geom_sf(data = p, fill = NA) +
# Force crs to be 3857
coord_sf(crs = 3857) +
labs(
@@ -372,20 +358,9 @@ library(tidyterra)
library(ggplot2)
library(sf)
-volcanotemp <- "volcano2hires.tif"
-
-# Download example file
-volcanourl <- paste0(
- "https://github.com/dieghernan/tidyterra/blob/main/",
- "data-raw/volcano2hires.tif?raw=true"
-)
-
-if (!file.exists(volcanotemp)) {
- download.file(volcanourl, volcanotemp, mode = "wb")
-}
+holyrood <- "holyroodpark.tif"
-
-r <- rast(volcanotemp)
+r <- rast(holyrood)
ggplot() +
geom_spatraster(data = r) +
@@ -419,19 +394,9 @@ library(tidyterra)
library(ggplot2)
library(sf)
-volcanotemp <- "volcano2hires.tif"
-
-# Download example file
-volcanourl <- paste0(
- "https://github.com/dieghernan/tidyterra/blob/main/",
- "data-raw/volcano2hires.tif?raw=true"
-)
-
-if (!file.exists(volcanotemp)) {
- download.file(volcanourl, volcanotemp, mode = "wb")
-}
+holyrood <- "holyroodpark.tif"
-r <- rast(volcanotemp)
+r <- rast(holyrood)
ggplot() +
geom_spatraster(data = r) +
@@ -449,11 +414,11 @@ ext <- r %>%
ggplot() +
geom_spatraster(data = r) +
- scale_y_continuous(
+ scale_x_continuous(
expand = expansion(mult = 0.05),
- breaks = scales::breaks_pretty(n = 3)(ext[c("ymin", "ymax")])
+ breaks = scales::breaks_pretty(n = 3)(ext[c("xmin", "xmax")])
) +
- labs(title = "Three breaks on y")
+ labs(title = "Three breaks on x (¿?)")
```
## Plotting a `SpatRaster` with color tables
@@ -527,19 +492,9 @@ library(tidyterra)
library(ggplot2)
library(ggspatial)
-volcanotemp <- "volcano2hires.tif"
+holyrood <- "holyroodpark.tif"
-# Download example file
-volcanourl <- paste0(
- "https://github.com/dieghernan/tidyterra/blob/main/",
- "data-raw/volcano2hires.tif?raw=true"
-)
-
-if (!file.exists(volcanotemp)) {
- download.file(volcanourl, volcanotemp, mode = "wb")
-}
-
-r <- rast(volcanotemp)
+r <- rast(holyrood)
autoplot(r) +
annotation_north_arrow(
@@ -669,19 +624,9 @@ library(terra)
library(tidyterra)
library(ggplot2)
-volcanotemp <- "volcano2hires.tif"
-
-# Download example file
-volcanourl <- paste0(
- "https://github.com/dieghernan/tidyterra/blob/main/",
- "data-raw/volcano2hires.tif?raw=true"
-)
-
-if (!file.exists(volcanotemp)) {
- download.file(volcanourl, volcanotemp, mode = "wb")
-}
+holyrood <- "holyroodpark.tif"
-r <- rast(volcanotemp)
+r <- rast(holyrood)
# With hex grid
ggplot(r, aes(x, y, z = elevation)) +
@@ -736,20 +681,9 @@ library(tidyterra)
library(ggplot2)
library(metR)
-volcanotemp <- "volcano2hires.tif"
-
-# Download example file
-volcanourl <- paste0(
- "https://github.com/dieghernan/tidyterra/blob/main/",
- "data-raw/volcano2hires.tif?raw=true"
-)
-
-if (!file.exists(volcanotemp)) {
- download.file(volcanourl, volcanotemp, mode = "wb")
-}
-
+holyrood <- "holyroodpark.tif"
-r <- rast(volcanotemp)
+r <- rast(holyrood)
```
#### `metR::geom_contour_tanaka()`
@@ -757,7 +691,7 @@ r <- rast(volcanotemp)
```{r tanaka}
ggplot(r, aes(x, y)) +
geom_spatraster(data = r, inherit.aes = FALSE) +
- geom_contour_tanaka(aes(z = elevation), breaks = seq(70, 200, 5)) +
+ geom_contour_tanaka(aes(z = elevation), breaks = seq(0, 250, 25)) +
scale_fill_viridis_c(option = "magma") +
labs(x = "", y = "", title = "tidyterra and metR: tanaka contours")
@@ -765,10 +699,10 @@ ggplot(r, aes(x, y)) +
ggplot(r, aes(x, y)) +
geom_spatraster_contour_filled(
data = r, inherit.aes = FALSE,
- breaks = seq(60, 200, 20)
+ breaks = seq(0, 250, 50)
) +
geom_contour_tanaka(aes(z = elevation),
- breaks = seq(70, 200, 5),
+ breaks = seq(0, 250, 10),
sun.angle = -90, dark = "gray50"
) +
scale_fill_viridis_d(option = "cividis") +
@@ -787,7 +721,7 @@ ggplot(r, aes(x, y)) +
data = r, inherit.aes = FALSE,
aes(alpha = after_stat(value))
) +
- scale_fill_cross_blended_c(breaks = seq(100, 200, 20)) +
+ scale_fill_cross_blended_c(breaks = seq(0, 250, 25)) +
scale_alpha(range = c(1, 0.25)) +
guides(alpha = "none", fill = guide_legend(reverse = TRUE)) +
labs(x = "", y = "", title = "tidyterra and metR: reliefs")
diff --git a/vignettes/articles/holyroodpark.tif b/vignettes/articles/holyroodpark.tif
new file mode 100644
index 00000000..78f37af6
Binary files /dev/null and b/vignettes/articles/holyroodpark.tif differ
diff --git a/vignettes/articles/volcano2hires.tif b/vignettes/articles/volcano2hires.tif
deleted file mode 100644
index f84dab70..00000000
Binary files a/vignettes/articles/volcano2hires.tif and /dev/null differ