diff --git a/DESCRIPTION b/DESCRIPTION index 7d389ec..a01e178 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,13 @@ Package: tmaptools Type: Package Title: Thematic Map Tools -Version: 3.1-1 +Version: 3.2 Authors@R: person("Martijn", "Tennekes", email = "mtennekes@gmail.com", role = c("aut", "cre")) 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: 2021-01-19 +Date: 2025-01-03 Depends: R (>= 3.5), methods @@ -25,6 +25,7 @@ Imports: XML Suggests: tmap (>= 3.0), + cols4all, rmapshaper, osmdata, OpenStreetMap, diff --git a/R/palette_explorer.R b/R/palette_explorer.R index aefc1b0..c3c09dc 100644 --- a/R/palette_explorer.R +++ b/R/palette_explorer.R @@ -95,7 +95,9 @@ is_light <- function(col) { -#' Explore color palettes +#' Explore color palettes (deprecated) +#' +#' This interactive tool has become deprecated and will not be maintained anymore. Please use \code{\link[cols4all:c4a_gui]{c4a_gui}} instead. #' #' \code{palette_explorer()} starts an interactive tool shows all Color Brewer and viridis palettes, where the number of colors can be adjusted as well as the constrast range. Categorical (qualitative) palettes can be stretched when the number of colors exceeds the number of palette colors. Output code needed to get the desired color values is generated. Finally, all colors can be tested for color blindness. The data.frame \code{tmap.pal.info} is similar to \code{\link[RColorBrewer:ColorBrewer]{brewer.pal.info}}, but extended with the color palettes from viridis. #' @export @@ -111,6 +113,8 @@ palette_explorer <- function() { if (!requireNamespace("shiny")) stop("shiny package needed for this function to work. Please install it.", call. = FALSE) if (!requireNamespace("shinyjs")) stop("shinyjs package needed for this function to work. Please install it.", call. = FALSE) + message("This tool is deprecated; please use cols4all::c4a_gui() instead") + shiny::shinyApp(ui = shiny::fluidPage( shinyjs::useShinyjs(), shiny::div( diff --git a/examples/approx_areas.R b/examples/approx_areas.R index bceb72a..d4a3a98 100644 --- a/examples/approx_areas.R +++ b/examples/approx_areas.R @@ -1,10 +1,11 @@ -if (require(tmap) && packageVersion("tmap") >= "2.0") { +if (require(tmap) && packageVersion("tmap") >= "3.99") { data(NLD_muni) NLD_muni$area <- approx_areas(NLD_muni, total.area = 33893) tm_shape(NLD_muni) + - tm_bubbles(size="area", title.size=expression("Area in " * km^2)) + tm_bubbles(size="area", + size.legend = tm_legend(title = expression("Area in " * km^2))) # function that returns min, max, mean and sum of area values diff --git a/examples/bb.R b/examples/bb.R index 970b078..50b2793 100644 --- a/examples/bb.R +++ b/examples/bb.R @@ -22,8 +22,8 @@ if (require(tmap) && packageVersion("tmap") >= "2.0") { \dontrun{ if (require(tmap)) { - bb("Limburg", projection = "rd") - bb_italy <- bb("Italy", projection = "eck4") + bb("Limburg", projection = 28992) + bb_italy <- bb("Italy", projection = "+proj=eck4") tm_shape(World, bbox=bb_italy) + tm_polygons() # shorter alternative: tm_shape(World, bbox="Italy") + tm_polygons() diff --git a/examples/calc_densities.R b/examples/calc_densities.R index 295fa73..f01ce1c 100644 --- a/examples/calc_densities.R +++ b/examples/calc_densities.R @@ -1,13 +1,13 @@ -if (require(tmap) && packageVersion("tmap") >= "2.0") { +if (require(tmap) && packageVersion("tmap") >= "3.99") { data(NLD_muni) NLD_muni_pop_per_km2 <- calc_densities(NLD_muni, - target = "km km", var = c("pop_men", "pop_women")) + 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("pop_men_km.2", "pop_women_km.2"), - title=expression("Population per " * km^2), style="quantile") + - tm_facets(free.scales = FALSE) + - tm_layout(panel.show = TRUE, panel.labels=c("Men", "Women")) + 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) } diff --git a/examples/crop_shape.R b/examples/crop_shape.R index 6e284bd..d7d18ad 100644 --- a/examples/crop_shape.R +++ b/examples/crop_shape.R @@ -1,4 +1,4 @@ -if (require(tmap) && packageVersion("tmap") >= "2.0") { +if (require(tmap) && packageVersion("tmap") >= "3.99") { data(World, NLD_muni, land, metro) #land_NLD <- crop_shape(land, NLD_muni) @@ -9,6 +9,8 @@ if (require(tmap) && packageVersion("tmap") >= "2.0") { qtm(World) + tm_shape(metro_Europe) + - tm_bubbles("pop2010", col="red", title.size="European cities") + + tm_bubbles("pop2010", + col="red", + size.legend = tm_legend("European cities")) + tm_legend(frame=TRUE) } diff --git a/examples/map_coloring.R b/examples/map_coloring.R index cd807ee..11ec146 100644 --- a/examples/map_coloring.R +++ b/examples/map_coloring.R @@ -1,4 +1,4 @@ -if (require(tmap) && packageVersion("tmap") >= "2.0") { +if (require(tmap) && packageVersion("tmap") >= "3.99") { data(World, metro) World$color <- map_coloring(World, palette="Pastel2") @@ -8,12 +8,15 @@ if (require(tmap) && packageVersion("tmap") >= "2.0") { data(NLD_prov, NLD_muni) tm_shape(NLD_prov) + - tm_fill("name", legend.show = FALSE) + + tm_fill("name", + fill.legend = tm_legend_hide()) + tm_shape(NLD_muni) + - tm_polygons("MAP_COLORS", palette="Greys", alpha = .25) + + tm_polygons("MAP_COLORS", + fill_alpha = .25, + fill.scale = tm_scale(values = "brewer.greys")) + tm_shape(NLD_prov) + tm_borders(lwd=2) + - tm_text("name", shadow=TRUE) + - tm_format("NLD", title="Dutch provinces and\nmunicipalities", bg.color="white") + tm_text("name", options = opt_tm_text(shadow = TRUE)) + + tm_title("Dutch provinces and\nmunicipalities", bg.color="white") } diff --git a/man/approx_areas.Rd b/man/approx_areas.Rd index c8a26aa..f8f5cbf 100644 --- a/man/approx_areas.Rd +++ b/man/approx_areas.Rd @@ -30,13 +30,14 @@ Approximate the area sizes of the polygons in real-world area units (such as sq Note that the method of determining areas is an approximation, since it depends on the used projection and the level of detail of the shape object. Projections with equal-area property are highly recommended. See \url{https://en.wikipedia.org/wiki/List_of_map_projections} for equal area world map projections. } \examples{ -if (require(tmap) && packageVersion("tmap") >= "2.0") { +if (require(tmap) && packageVersion("tmap") >= "3.99") { data(NLD_muni) NLD_muni$area <- approx_areas(NLD_muni, total.area = 33893) tm_shape(NLD_muni) + - tm_bubbles(size="area", title.size=expression("Area in " * km^2)) + tm_bubbles(size="area", + size.legend = tm_legend(title = expression("Area in " * km^2))) # function that returns min, max, mean and sum of area values diff --git a/man/bb.Rd b/man/bb.Rd index 627717e..0d7a69c 100644 --- a/man/bb.Rd +++ b/man/bb.Rd @@ -102,8 +102,8 @@ if (require(tmap) && packageVersion("tmap") >= "2.0") { \dontrun{ if (require(tmap)) { - bb("Limburg", projection = "rd") - bb_italy <- bb("Italy", projection = "eck4") + bb("Limburg", projection = 28992) + bb_italy <- bb("Italy", projection = "+proj=eck4") tm_shape(World, bbox=bb_italy) + tm_polygons() # shorter alternative: tm_shape(World, bbox="Italy") + tm_polygons() diff --git a/man/calc_densities.Rd b/man/calc_densities.Rd index 5a8a067..e00a706 100644 --- a/man/calc_densities.Rd +++ b/man/calc_densities.Rd @@ -33,18 +33,18 @@ Vector or data.frame (depending on whether \code{length(var)==1} with density va 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. } \examples{ -if (require(tmap) && packageVersion("tmap") >= "2.0") { +if (require(tmap) && packageVersion("tmap") >= "3.99") { data(NLD_muni) NLD_muni_pop_per_km2 <- calc_densities(NLD_muni, - target = "km km", var = c("pop_men", "pop_women")) + 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("pop_men_km.2", "pop_women_km.2"), - title=expression("Population per " * km^2), style="quantile") + - tm_facets(free.scales = FALSE) + - tm_layout(panel.show = TRUE, panel.labels=c("Men", "Women")) + 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) } } \keyword{densities} diff --git a/man/crop_shape.Rd b/man/crop_shape.Rd index 666e5b6..ccb88e8 100644 --- a/man/crop_shape.Rd +++ b/man/crop_shape.Rd @@ -25,7 +25,7 @@ Crop a shape object (from class \code{\link[sf:sf]{sf}}, \code{\link[stars:st_as This function is similar to \code{crop} from the \code{raster} package. The main difference is that \code{crop_shape} also allows to crop using a polygon instead of a rectangle. } \examples{ -if (require(tmap) && packageVersion("tmap") >= "2.0") { +if (require(tmap) && packageVersion("tmap") >= "3.99") { data(World, NLD_muni, land, metro) #land_NLD <- crop_shape(land, NLD_muni) @@ -36,7 +36,9 @@ if (require(tmap) && packageVersion("tmap") >= "2.0") { qtm(World) + tm_shape(metro_Europe) + - tm_bubbles("pop2010", col="red", title.size="European cities") + + tm_bubbles("pop2010", + col="red", + size.legend = tm_legend("European cities")) + tm_legend(frame=TRUE) } } diff --git a/man/map_coloring.Rd b/man/map_coloring.Rd index e79d1c2..48867cb 100644 --- a/man/map_coloring.Rd +++ b/man/map_coloring.Rd @@ -33,7 +33,7 @@ If \code{palette} is defined, a vector of colors is returned, otherwise a vector Color the polygons of a map such that adjacent polygons have different colors } \examples{ -if (require(tmap) && packageVersion("tmap") >= "2.0") { +if (require(tmap) && packageVersion("tmap") >= "3.99") { data(World, metro) World$color <- map_coloring(World, palette="Pastel2") @@ -43,13 +43,16 @@ if (require(tmap) && packageVersion("tmap") >= "2.0") { data(NLD_prov, NLD_muni) tm_shape(NLD_prov) + - tm_fill("name", legend.show = FALSE) + + tm_fill("name", + fill.legend = tm_legend_hide()) + tm_shape(NLD_muni) + - tm_polygons("MAP_COLORS", palette="Greys", alpha = .25) + + tm_polygons("MAP_COLORS", + fill_alpha = .25, + fill.scale = tm_scale(values = "brewer.greys")) + tm_shape(NLD_prov) + tm_borders(lwd=2) + - tm_text("name", shadow=TRUE) + - tm_format("NLD", title="Dutch provinces and\nmunicipalities", bg.color="white") + tm_text("name", options = opt_tm_text(shadow = TRUE)) + + tm_title("Dutch provinces and\nmunicipalities", bg.color="white") } } diff --git a/man/palette_explorer.Rd b/man/palette_explorer.Rd index ce7dad0..3dea467 100644 --- a/man/palette_explorer.Rd +++ b/man/palette_explorer.Rd @@ -4,7 +4,7 @@ \name{palette_explorer} \alias{palette_explorer} \alias{tmap.pal.info} -\title{Explore color palettes} +\title{Explore color palettes (deprecated)} \format{ An object of class \code{data.frame} with 40 rows and 4 columns. } @@ -14,6 +14,9 @@ palette_explorer() tmap.pal.info } \description{ +This interactive tool has become deprecated and will not be maintained anymore. Please use \code{\link[cols4all:c4a_gui]{c4a_gui}} instead. +} +\details{ \code{palette_explorer()} starts an interactive tool shows all Color Brewer and viridis palettes, where the number of colors can be adjusted as well as the constrast range. Categorical (qualitative) palettes can be stretched when the number of colors exceeds the number of palette colors. Output code needed to get the desired color values is generated. Finally, all colors can be tested for color blindness. The data.frame \code{tmap.pal.info} is similar to \code{\link[RColorBrewer:ColorBrewer]{brewer.pal.info}}, but extended with the color palettes from viridis. } \examples{ diff --git a/man/pipe.Rd b/man/pipe.Rd index c763717..f7e15b8 100644 --- a/man/pipe.Rd +++ b/man/pipe.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pkg.R +% Please edit documentation in R/tmaptools-package.R \name{\%>\%} \alias{\%>\%} \title{Pipe operator} diff --git a/man/tmaptools-package.Rd b/man/tmaptools-package.Rd index 9d601fb..e237df1 100644 --- a/man/tmaptools-package.Rd +++ b/man/tmaptools-package.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pkg.R +% Please edit documentation in R/tmaptools-package.R \docType{package} \name{tmaptools-package} \alias{tmaptools}