diff --git a/.Rbuildignore b/.Rbuildignore index 6c7143b..1db58fc 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -15,3 +15,4 @@ appveyor.yml ^docs$ ^pkgdown$ ^\.github$ +^CRAN-SUBMISSION$ diff --git a/DESCRIPTION b/DESCRIPTION index 1a46da6..c5b91d8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,8 +6,7 @@ Authors@R: person("Martijn", "Tennekes", email = "mtennekes@gmail.com", role = c Description: Set of tools for reading and processing spatial data. The aim is to supply the workflow to create thematic maps. This package also facilitates 'tmap', the package for visualizing thematic maps. License: GPL-3 Encoding: UTF-8 -LazyData: true -Date: 2025-01-03 +Date: 2025-01-13 Depends: R (>= 3.5), methods diff --git a/NEWS.md b/NEWS.md index beb44c4..f17ddfb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# version 3.2 +- examples updated with tmap4 +- deprecated some functions + # version 3.1-1 - fixed minor bugs (see github) diff --git a/R/calc_densities.R b/R/calc_densities.R index cd414d2..2701d54 100644 --- a/R/calc_densities.R +++ b/R/calc_densities.R @@ -2,7 +2,7 @@ #' #' Transpose quantitative variables to densitiy variables, which are often needed for choroplets. For example, the colors of a population density map should correspond population density counts rather than absolute population numbers. #' -#' @param shp a shape object, i.e., an \code{\link[sf:sf]{sf}} object or a \code{SpatialPolygons(DataFrame)} from the \code{sp} package. +#' @param shp a shape object, i.e., an \code{\link[sf:sf]{sf}} object. #' @param var name(s) of a qualtity variable name contained in the \code{shp} data #' @param target the target unit, see \code{\link{approx_areas}}. Density values are calculated in \code{var/target^2}. #' @param total.area total area size of \code{shp} in number of target units (defined by \code{unit}), \code{\link{approx_areas}}. diff --git a/R/get_brewer_pal.R b/R/get_brewer_pal.R index bd245b5..2a81873 100644 --- a/R/get_brewer_pal.R +++ b/R/get_brewer_pal.R @@ -1,6 +1,6 @@ -#' Get and plot a (modified) Color Brewer palette +#' Get and plot a (modified) Color Brewer palette (deprecated) #' -#' Get and plot a (modified) palette from Color Brewer. In addition to the base function \code{\link[RColorBrewer:ColorBrewer]{brewer.pal}}, a palette can be created for any number of classes. The contrast of the palette can be adjusted for sequential and diverging palettes. For categorical palettes, intermediate colors can be generated. An interactive tool that uses this function is \code{\link{palette_explorer}}. +#' Get and plot a (modified) palette from Color Brewer. This function is deprecated. Please use \code{\link[cols4all:c4a]{c4a}} instead. #' #' The default contrast of the palette depends on the number of colors, \code{n}, in the following way. The default contrast is maximal, so \code{(0, 1)}, when \code{n = 9} for sequential palettes and \code{n = 11} for diverging palettes. The default contrast values for smaller values of \code{n} can be extracted with some R magic: \code{sapply(1:9, tmaptools:::default_contrast_seq)} for sequential palettes and \code{sapply(1:11, tmaptools:::default_contrast_div)} for diverging palettes. #' @@ -16,6 +16,9 @@ #' @importFrom RColorBrewer brewer.pal brewer.pal.info #' @export get_brewer_pal <- function(palette, n=5, contrast=NA, stretch=TRUE, plot=TRUE) { + + message("This function is deprecated; please use cols4all::c4a() instead") + call <- names(match.call(expand.dots = TRUE)[-1]) reverse <- (substr(palette, 1, 1) == "-") diff --git a/examples/calc_densities.R b/examples/calc_densities.R index f01ce1c..0270766 100644 --- a/examples/calc_densities.R +++ b/examples/calc_densities.R @@ -1,13 +1,17 @@ if (require(tmap) && packageVersion("tmap") >= "3.99") { - data(NLD_muni) +data(NLD_muni) - NLD_muni_pop_per_km2 <- calc_densities(NLD_muni, - target = "km km", var = c("population", "dwelling_total")) - NLD_muni <- sf::st_sf(data.frame(NLD_muni, NLD_muni_pop_per_km2)) +NLD_muni_pop_per_km2 <- calc_densities(NLD_muni, + target = "km km", var = c("population", "dwelling_total")) +NLD_muni <- sf::st_sf(data.frame(NLD_muni, NLD_muni_pop_per_km2)) - tm_shape(NLD_muni) + - tm_polygons(c("population_km.2", "dwelling_total_km.2"), - fill.legend = list(tm_legend(expression("Population per " * km^2)), tm_legend(expression("Dwellings per " * km^2)))) + - tm_facets(free.scales = TRUE) + - tm_layout(panel.show = FALSE) +tm_shape(NLD_muni) + + tm_polygons( + fill = c("population_km.2", "dwelling_total_km.2"), + fill.legend = + list( + tm_legend(expression("Population per " * km^2)), + tm_legend(expression("Dwellings per " * km^2)))) + +tm_facets(free.scales = TRUE) + + tm_layout(panel.show = FALSE) } diff --git a/man/calc_densities.Rd b/man/calc_densities.Rd index e00a706..9135f3f 100644 --- a/man/calc_densities.Rd +++ b/man/calc_densities.Rd @@ -14,7 +14,7 @@ calc_densities( ) } \arguments{ -\item{shp}{a shape object, i.e., an \code{\link[sf:sf]{sf}} object or a \code{SpatialPolygons(DataFrame)} from the \code{sp} package.} +\item{shp}{a shape object, i.e., an \code{\link[sf:sf]{sf}} object.} \item{var}{name(s) of a qualtity variable name contained in the \code{shp} data} @@ -34,17 +34,21 @@ Transpose quantitative variables to densitiy variables, which are often needed f } \examples{ if (require(tmap) && packageVersion("tmap") >= "3.99") { - data(NLD_muni) +data(NLD_muni) - NLD_muni_pop_per_km2 <- calc_densities(NLD_muni, - target = "km km", var = c("population", "dwelling_total")) - NLD_muni <- sf::st_sf(data.frame(NLD_muni, NLD_muni_pop_per_km2)) +NLD_muni_pop_per_km2 <- calc_densities(NLD_muni, + target = "km km", var = c("population", "dwelling_total")) +NLD_muni <- sf::st_sf(data.frame(NLD_muni, NLD_muni_pop_per_km2)) - tm_shape(NLD_muni) + - tm_polygons(c("population_km.2", "dwelling_total_km.2"), - fill.legend = list(tm_legend(expression("Population per " * km^2)), tm_legend(expression("Dwellings per " * km^2)))) + - tm_facets(free.scales = TRUE) + - tm_layout(panel.show = FALSE) +tm_shape(NLD_muni) + + tm_polygons( + fill = c("population_km.2", "dwelling_total_km.2"), + fill.legend = + list( + tm_legend(expression("Population per " * km^2)), + tm_legend(expression("Dwellings per " * km^2)))) + +tm_facets(free.scales = TRUE) + + tm_layout(panel.show = FALSE) } } \keyword{densities} diff --git a/man/get_brewer_pal.Rd b/man/get_brewer_pal.Rd index 11f68aa..e35f55b 100644 --- a/man/get_brewer_pal.Rd +++ b/man/get_brewer_pal.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/get_brewer_pal.R \name{get_brewer_pal} \alias{get_brewer_pal} -\title{Get and plot a (modified) Color Brewer palette} +\title{Get and plot a (modified) Color Brewer palette (deprecated)} \usage{ get_brewer_pal(palette, n = 5, contrast = NA, stretch = TRUE, plot = TRUE) } @@ -21,7 +21,7 @@ get_brewer_pal(palette, n = 5, contrast = NA, stretch = TRUE, plot = TRUE) vector of color values. It is silently returned when \code{plot=TRUE}. } \description{ -Get and plot a (modified) palette from Color Brewer. In addition to the base function \code{\link[RColorBrewer:ColorBrewer]{brewer.pal}}, a palette can be created for any number of classes. The contrast of the palette can be adjusted for sequential and diverging palettes. For categorical palettes, intermediate colors can be generated. An interactive tool that uses this function is \code{\link{palette_explorer}}. +Get and plot a (modified) palette from Color Brewer. This function is deprecated. Please use \code{\link[cols4all:c4a]{c4a}} instead. } \details{ The default contrast of the palette depends on the number of colors, \code{n}, in the following way. The default contrast is maximal, so \code{(0, 1)}, when \code{n = 9} for sequential palettes and \code{n = 11} for diverging palettes. The default contrast values for smaller values of \code{n} can be extracted with some R magic: \code{sapply(1:9, tmaptools:::default_contrast_seq)} for sequential palettes and \code{sapply(1:11, tmaptools:::default_contrast_div)} for diverging palettes.