Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ types enable a variety of additional features. (#222 @vincentarelbundock)
of the x and y axes. This should work regardless of plot type, e.g.
`plt(~Sepal.Length | Species, data = iris, type = "density", flip = TRUE)`.
(#216 @grantmcdermott)
- `tpar()` gains additional `grid.col`, `grid.lty`, and `grid.lwd` arguments for
fine-grained control over the appearance of the default panel grid when
`plt(..., grid = TRUE)` is called. (#237 @grantmcdermott)

Bug fixes:

Expand Down
6 changes: 3 additions & 3 deletions R/facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ draw_facet_window = function(grid, ...) {
xg = pretty(as.Date(round(extendrange(xlim)), tz = tz))
}
}
abline(v = xg, col = "lightgray", lty = "dotted", lwd = par("lwd"))
abline(v = xg, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]])
gnx = NA
}
if (!any(c(par("ylog"), type == "boxplot"))) {
Expand All @@ -439,10 +439,10 @@ draw_facet_window = function(grid, ...) {
yg = pretty(as.Date(extendrange(ylim), tz = tz))
}
}
abline(h = yg, col = "lightgray", lty = "dotted", lwd = par("lwd"))
abline(h = yg, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]])
gny = NA
}
grid(nx = gnx, ny = gny)
grid(nx = gnx, ny = gny, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]])
}
} else {
grid
Expand Down
26 changes: 26 additions & 0 deletions R/tpar.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
#' `grid` \tab\tab Logical indicating whether a background panel grid should be added to plots automatically. Defaults to NULL, which is equivalent to `FALSE`.\cr
#' \tab\tab\cr
#' \tab\tab\cr
#' `grid.col` \tab\tab Character or (integer) numeric that specifies the color of the panel grid lines. Defaults to `"lightgray"`.\cr
#' \tab\tab\cr
#' \tab\tab\cr
#' `grid.lty` \tab\tab Character or (integer) numeric that specifies the line type of the panel grid lines. Defaults to `"dotted"`.\cr
#' \tab\tab\cr
#' \tab\tab\cr
#' `grid.lwd` \tab\tab Non-negative numeric giving the line of the panel grid lines. Defaults to `1`.\cr
#' \tab\tab\cr
#' \tab\tab\cr
#' `lmar` \tab\tab A numeric vector of form `c(inner, outer)` that gives the margin padding, in terms of lines, around the automatic `tinyplot` legend. Defaults to `c(1.0, 0.1)`, where the first number represents the "inner" margin between the legend and the plot region, and the second number represents the "outer" margin between the legend and edge of the graphics device. (Note that an exception for the definition of the "outer" legend margin occurs when the legend placement is `"top!"`, since the legend is placed above the plot region but below the main title. In such cases, the outer margin is relative to the existing gap between the title and the plot region, which is itself determined by `par("mar")[3]`.)\cr
#' \tab\tab\cr
#' \tab\tab\cr
Expand Down Expand Up @@ -213,6 +222,23 @@ tpar = function(...) {
.tpar$grid = grid
}

if (length(opts$grid.col)) {
grid.col = opts$grid.col
.tpar$grid.col = grid.col
}

if (length(opts$grid.lty)) {
grid.lty = opts$grid.lty
.tpar$grid.lty = grid.lty
}

if (length(opts$grid.lwd)) {
grid.lwd = as.numeric(opts$grid.lwd)
if(!is.numeric(grid.lwd) || grid.lwd < 0) stop("grid.lwd needs to be a non-negative numeric")
.tpar$grid.lwd = grid.lwd
}


if (length(opts$lmar)) {
lmar = as.numeric(opts$lmar)
if(!is.numeric(lmar)) stop("lmar needs to be numeric")
Expand Down
3 changes: 3 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

# Plot grid
.tpar$grid = if(is.null(getOption("tinyplot_grid"))) FALSE else as.logical(getOption("tinyplot_grid"))
.tpar$grid.col = if(is.null(getOption("tinyplot_grid.col"))) "lightgray" else getOption("tinyplot_grid.col")
.tpar$grid.lty = if(is.null(getOption("tinyplot_grid.lty"))) "dotted" else getOption("tinyplot_grid.lty")
.tpar$grid.lwd = if(is.null(getOption("tinyplot_grid.lwd"))) 1 else as.numeric(getOption("tinyplot_grid.lwd"))

# Legend margin, i.e. gap between the legend and the plot elements
.tpar$lmar = if(is.null(getOption("tinyplot_lmar"))) c(1.0, 0.1) else as.numeric(getOption("tinyplot_lmar"))
Expand Down
83 changes: 83 additions & 0 deletions inst/tinytest/_tinysnapshot/tpar_grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions inst/tinytest/test-tpar.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source("helpers.R")
using("tinysnapshot")

f = function () {
op = tpar(grid = TRUE, grid.col = "hotpink", grid.lty = "solid", grid.lwd = 2)
tinyplot(0:10, pch = 19)
tpar(op)
}
expect_snapshot_plot(f, label = "tpar_grid")
9 changes: 9 additions & 0 deletions man/tpar.Rd

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