diff --git a/R/process_meta.R b/R/process_meta.R index 7057b556..016332ca 100644 --- a/R/process_meta.R +++ b/R/process_meta.R @@ -40,8 +40,24 @@ preprocess_meta = function(o, cdt) { isdef = !sapply(fl, is.null) n = prod(nby) - if (is.na(panel.type)) panel.type = ifelse(((type == "page" || n == 1) && is.na(panel.labels[[1]]) && !identical(panel.show, TRUE)) || ((type %in% c("wrap", "stack")) && !isdef[1]) || (!(type %in% c("wrap", "stack")) && !isdef[1] && !isdef[2]) || !o$panel.show, "none", - ifelse((type %in% c("wrap", "stack")) || (n == 1) || (type == "page" && identical(panel.show, TRUE)), "wrap", "xtab")) + if (is.na(panel.type)) panel.type = if (identical(panel.show, FALSE)) { + "none" + } else if (identical(panel.show, TRUE)) { + # force panel labels + if (type %in% c("wrap", "stack", "page") || (n == 1)) { + "wrap" + } else { + "xtab" + } + } else if ((type == "page" || n == 1) && is.na(panel.labels[[1]])) { + "none" + } else if (!(type %in% c("wrap", "stack")) && !isdef[1] && !isdef[2]) { + "none" + } else if ((type %in% c("wrap", "stack")) || (n == 1)) { + "wrap" + } else { + "xtab" + } inner.margins = get_option_class(inner.margins, class = main_class) diff --git a/R/tmap_options.R b/R/tmap_options.R index cc9322ec..52a26c71 100644 --- a/R/tmap_options.R +++ b/R/tmap_options.R @@ -577,7 +577,7 @@ tmapMode = function(id, name, ...) { minimap.position = tm_pos_in(pos.h = "right", pos.v = "bottom", align.h = "right", align.v = "top", just.h = "left", just.v = "bottom"), minimap.show = FALSE, - panel.show = TRUE, + panel.show = NA, # depends on type: TRUE for facets panel.labels = NA, panel.label.size = 1, panel.label.color = "black", diff --git a/tests/testing_panels.Rmd b/tests/testing_panels.Rmd new file mode 100644 index 00000000..11c58667 --- /dev/null +++ b/tests/testing_panels.Rmd @@ -0,0 +1,105 @@ +--- +title: "Testing - Panel labels" +author: "Martijn Tennekes" +date: "`r Sys.Date()`" +output: html_document +editor_options: + chunk_output_type: console +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE, fig.width = 9) +library(tmap) +``` + + + +### Single map + +```{r} +# default: no panels +tm_shape(World) + + tm_polygons("HPI") +``` + +```{r} +# with +tm_shape(World) + + tm_polygons("HPI") + + tm_layout(panel.show = TRUE) +``` + +### Facets defined with multiple variables + +```{r} +# default: with panels +tm_shape(World) + + tm_polygons(c("HPI", "footprint")) +``` + +```{r} +# without +tm_shape(World) + + tm_polygons(c("HPI", "footprint")) + + tm_layout(panel.show = FALSE) +``` + + +```{r} +# default: with panels +tm_shape(World) + + tm_polygons("HPI") + + tm_facets("continent") + + +### Facets defined with multiple variables, single pages + + +```{r} +# default: without +tm_shape(World) + + tm_polygons(c("HPI", "footprint")) + + tm_facets_pagewise() + +```{r} +# with +tm_shape(World) + + tm_polygons(c("HPI", "footprint")) + + tm_facets_pagewise() + + tm_layout(panel.show = TRUE) +``` + +### Facets defined with 'by' variable + +```{r} +# default: with +tm_shape(World) + + tm_polygons("HPI") + + tm_facets("continent") +``` + +```{r} +# without +tm_shape(World) + + tm_polygons("HPI") + + tm_facets("continent") + + tm_layout(panel.show = FALSE) +``` + +### Facet grid + +```{r} +# default: with panels +tm_shape(World) + + tm_polygons("HPI") + + tm_facets_grid("continent", "economy") +``` + +```{r} +# without +tm_shape(World) + + tm_polygons("HPI") + + tm_facets_grid("continent", "economy") + + tm_layout(panel.show = FALSE) +``` +