Skip to content

Commit

Permalink
update to tmap4
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Jan 3, 2025
1 parent 9dc3d5f commit 9448c6d
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 40 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", 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
Expand All @@ -25,6 +25,7 @@ Imports:
XML
Suggests:
tmap (>= 3.0),
cols4all,
rmapshaper,
osmdata,
OpenStreetMap,
Expand Down
6 changes: 5 additions & 1 deletion R/palette_explorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions examples/approx_areas.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/bb.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions examples/calc_densities.R
Original file line number Diff line number Diff line change
@@ -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)
}
6 changes: 4 additions & 2 deletions examples/crop_shape.R
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
}
13 changes: 8 additions & 5 deletions examples/map_coloring.R
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
}

5 changes: 3 additions & 2 deletions man/approx_areas.Rd

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

4 changes: 2 additions & 2 deletions man/bb.Rd

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

12 changes: 6 additions & 6 deletions man/calc_densities.Rd

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

6 changes: 4 additions & 2 deletions man/crop_shape.Rd

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

13 changes: 8 additions & 5 deletions man/map_coloring.Rd

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

5 changes: 4 additions & 1 deletion man/palette_explorer.Rd

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

2 changes: 1 addition & 1 deletion man/pipe.Rd

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

2 changes: 1 addition & 1 deletion man/tmaptools-package.Rd

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

0 comments on commit 9448c6d

Please sign in to comment.