Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Sep 26, 2024
1 parent 686f31b commit aefe37f
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
20 changes: 18 additions & 2 deletions R/process_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion R/tmap_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
105 changes: 105 additions & 0 deletions tests/testing_panels.Rmd
Original file line number Diff line number Diff line change
@@ -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)
```

0 comments on commit aefe37f

Please sign in to comment.