Skip to content

Commit b3f5a60

Browse files
committed
allow mar to be set in a plot.sf call; #2558
1 parent a3de3df commit b3f5a60

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# version 1.0-24
22

3+
* the figure margins parameter `mar` can be specified in a call to `plot.sf()`; #2558
4+
35
* fix class label setting in `[.sf()`; #2557
46

57
# version 1.0-23

R/plot.R

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ sf_cut = function(values, breaks, include.lowest = TRUE) {
6969
#' When setting \code{reset} to \code{FALSE}, the original device parameters are lost, and the device must be reset using \code{dev.off()} in order to reset it.
7070
#'
7171
#' parameter \code{at} can be set to specify where labels are placed along the key; see examples.
72+
#'
73+
#' parameter \code{mar} can be set in \code{...} to override default margins.
7274
#'
7375
#' The features are plotted in the order as they apppear in the sf object. See examples for when a different plotting order is wanted.
7476
#'
@@ -139,10 +141,14 @@ plot.sf <- function(x, y, ..., main, pal = NULL, nbreaks = 10, breaks = "pretty"
139141
key.pos = lt$key.pos
140142
layout(lt$m, widths = lt$widths, heights = lt$heights, respect = compact)
141143

142-
if (isTRUE(dots$axes))
143-
par(mar = c(2.1, 2.1, 1.2, 0))
144-
else
145-
par(mar = c(0, 0, 1.2, 0))
144+
mar = if (is.null(dots$mar)) {
145+
if (isTRUE(dots$axes))
146+
c(2.1, 2.1, 1.2, 0)
147+
else
148+
c(0, 0, 1.2, 0)
149+
} else
150+
dots$mar
151+
par(mar = mar)
146152

147153
if (max_plot_missing)
148154
max.plot = prod(lt$mfrow)
@@ -302,9 +308,12 @@ plot.sf <- function(x, y, ..., main, pal = NULL, nbreaks = 10, breaks = "pretty"
302308
reset_layout_needed = FALSE # as we didn't call layout()
303309
# plot the map:
304310
if (!isTRUE(dots$add)) {
305-
mar = c(1, 1, 1.2, 1)
306-
if (isTRUE(dots$axes))
307-
mar[1:2] = 2.1
311+
if (is.null(dots$mar)) {
312+
mar = c(1, 1, 1.2, 1)
313+
if (isTRUE(dots$axes))
314+
mar[1:2] = 2.1
315+
} else
316+
mar = dots$mar
308317
par(mar = mar)
309318
}
310319
if (col_missing)

man/plot.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)