Skip to content

Commit

Permalink
Update release
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Apr 22, 2024
1 parent ddad548 commit 6ac5d5c
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 64 deletions.
38 changes: 21 additions & 17 deletions R/pivot-long-SpatVector.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,35 @@
#' have always the geometry of `data`.
#'
#' @examples
#' \donttest{
#'
#' library(dplyr)
#' library(tidyr)
#' library(ggplot2)
#' library(terra)
#'
#' nc <- terra::vect(system.file("shape/nc.shp", package = "sf"))
#'
#' # Usually this is useful for faceting, see BIR
#' glimpse(nc)
#' temp <- rast((system.file("extdata/cyl_temp.tif", package = "tidyterra")))
#' cyl <- vect(system.file("extdata/cyl.gpkg", package = "tidyterra")) %>%
#' project(temp)
#'
#' nc_pivoted <- nc %>%
#' pivot_longer(starts_with("BIR"),
#' names_to = "year",
#' values_to = "births"
#' ) %>%
#' mutate(year = as.numeric(gsub("BIR", "19", year)))
#' # Add average temp
#'
#' nc_pivoted %>%
#' relocate(year, births) %>%
#' temps <- terra::extract(temp, cyl, fun = "mean", na.rm = TRUE, xy = TRUE)
#' cyl_temp <- cbind(cyl, temps) %>%
#' glimpse()
#'
#' ggplot(nc_pivoted) +
#' geom_spatvector(aes(fill = births)) +
#' facet_wrap(~year, ncol = 1) +
#' scale_fill_viridis_c(option = "cividis") +
#' labs(title = "Number of births in South Carolina")
#' # And pivot long for plot
#' cyl_temp %>%
#' pivot_longer(
#' cols = tavg_04:tavg_06,
#' names_to = "label",
#' values_to = "temp"
#' ) %>%
#' ggplot() +
#' geom_spatvector(aes(fill = temp)) +
#' facet_wrap(~label, ncol = 1) +
#' scale_fill_whitebox_c(palette = "muted")
#' }
pivot_longer.SpatVector <- function(data, cols, ..., cols_vary = "fastest",
names_to = "name", names_prefix = NULL,
names_sep = NULL, names_pattern = NULL,
Expand Down
30 changes: 17 additions & 13 deletions R/pivot-wide-SpatVector.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,30 @@
#' have always the geometry of `data`.
#'
#' @examples
#'
#' \donttest{
#' library(dplyr)
#' library(tidyr)
#' library(ggplot2)
#'
#' nc <- terra::vect(system.file("shape/nc.shp", package = "sf"))
#'
#' names(nc)
#' # Pivot longer
#' nc_long <- nc %>%
#' pivot_longer(contains("BIR"), names_to = "label", values_to = "n") %>%
#' select(label:n) %>%
#' glimpse()
#'
#' cyl <- terra::vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
#'
#' # Undo
#' nc_long %>%
#' pivot_wider(names_from = label, values_from = n) %>%
#' # Add extra row with info
#' xtra <- cyl %>%
#' slice(c(2, 3)) %>%
#' mutate(
#' label = "extra",
#' value = TRUE
#' ) %>%
#' rbind(cyl, .) %>%
#' glimpse()
#'
#' # Pivot by geom
#' xtra %>%
#' pivot_wider(
#' id_cols = iso2:name, values_from = value,
#' names_from = label
#' )
#' }
pivot_wider.SpatVector <- function(data,
...,
id_cols = NULL,
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@
"SystemRequirements": null
},
"keywords": ["r", "terra", "ggplot-extension", "r-spatial", "rspatial", "r-package", "rstats", "rstats-package", "cran", "cran-r"],
"fileSize": "2289.359KB",
"fileSize": "2289.634KB",
"citation": [
{
"@type": "ScholarlyArticle",
Expand Down
4 changes: 2 additions & 2 deletions data-raw/holyroodpark.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ 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")
writeRaster(xtraclip, "data-raw/holyroodpark.tif")
writeRaster(xtraclip, "vignettes/articles/holyroodpark.tif")
Binary file modified data-raw/holyroodpark.tif
Binary file not shown.
38 changes: 21 additions & 17 deletions man/pivot_longer.SpatVector.Rd

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

30 changes: 17 additions & 13 deletions man/pivot_wider.SpatVector.Rd

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

2 changes: 1 addition & 1 deletion vignettes/articles/faqs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ blurriness on your data. Also, modify the parameter `maxcell` to avoid
resampling and force the **ggplot2** map to be on **EPSG:3857** with
`ggplot2::coord_sf(crs = 3857)`:

```{r blurry-tile}
```{r blurry-tile, fig.show='hold'}
library(terra)
library(tidyterra)
library(ggplot2)
Expand Down
Binary file modified vignettes/articles/holyroodpark.tif
Binary file not shown.

0 comments on commit 6ac5d5c

Please sign in to comment.