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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where the formatting is also better._
- `type_text()` can now also deal with factor `x`/`y` variables by converting
them to numeric which helps to add text to barplots etc. (#470 @zeileis)
- Fix bug where sourced (non-interactive) scripts with `tinytheme()` calls were
not inheriting the correct LHS margin spacing. (#475 @grantmcdermott)
not inheriting the correct parameters and spacing. (#475, #481 @grantmcdermott)


### Internals
Expand Down
33 changes: 17 additions & 16 deletions R/facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ draw_facet_window = function(
type,
x, xmax, xmin,
y, ymax, ymin,
dynmar = NULL
tpars = NULL
) {

if (is.null(tpars)) tpars = tpar()

# if add is TRUE, just return inputs without any calculations
if (isTRUE(add)) {
return(as.list(environment()))
Expand All @@ -47,15 +49,14 @@ draw_facet_window = function(
if (!is.null(yaxb) && !is.null(ylabs)) ylabs = yaxb

# draw background color only in the grid rectangle
grid.bg = get_tpar("grid.bg")
grid.bg = get_tpar("grid.bg", tpar_list = tpars)
if (!is.null(grid.bg)) {
corners = par("usr")
rect(corners[1], corners[3], corners[2], corners[4], col = grid.bg, border = NA)
}

## dynamic margins flag
if (is.null(dynmar)) dynmar = get_tpar("dynmar")
dynmar = isTRUE(dynmar)
dynmar = isTRUE(get_tpar("dynmar", tpar_list = tpars))

## optionally allow to modify the style of axis interval calculation
if (!is.null(xaxs)) par(xaxs = xaxs)
Expand Down Expand Up @@ -263,17 +264,17 @@ draw_facet_window = function(
side = xside,
type = xaxt,
labeller = xaxl,
cex = get_tpar(c("cex.xaxs", "cex.axis"), 0.8),
lwd = get_tpar(c("lwd.xaxs", "lwd.axis"), 1),
lty = get_tpar(c("lty.xaxs", "lty.axis"), 1)
cex = get_tpar(c("cex.xaxs", "cex.axis"), 0.8, tpar_list = tpars),
lwd = get_tpar(c("lwd.xaxs", "lwd.axis"), 1, tpar_list = tpars),
lty = get_tpar(c("lty.xaxs", "lty.axis"), 1, tpar_list = tpars)
)
args_y = list(y,
side = yside,
type = yaxt,
labeller = yaxl,
cex = get_tpar(c("cex.yaxs", "cex.axis"), 0.8),
lwd = get_tpar(c("lwd.yaxs", "lwd.axis"), 1),
lty = get_tpar(c("lty.yaxs", "lty.axis"), 1)
cex = get_tpar(c("cex.yaxs", "cex.axis"), 0.8, tpar_list = tpars),
lwd = get_tpar(c("lwd.yaxs", "lwd.axis"), 1, tpar_list = tpars),
lty = get_tpar(c("lty.yaxs", "lty.axis"), 1, tpar_list = tpars)
)
if (!is.null(xaxb)) args_x$at = xaxb
if (!is.null(yaxb)) args_y$at = yaxb
Expand Down Expand Up @@ -475,7 +476,7 @@ draw_facet_window = function(
if (frame.plot) box()

# panel grid lines
if (is.null(grid)) grid = .tpar[["grid"]]
if (is.null(grid)) grid = get_tpar("grid", tpar_list = tpars)
if (!is.null(grid)) {
if (is.logical(grid)) {
## If grid is TRUE create a default grid. Rather than just calling the default grid()
Expand All @@ -485,22 +486,22 @@ draw_facet_window = function(
if (isTRUE(grid)) {
gnx = gny = NULL
if (!is.null(xaxb)) {
abline(v = xaxb, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]])
abline(v = xaxb, col = get_tpar("grid.col", tpar_list = tpars), lty = get_tpar("grid.lty", tpar_list = tpars), lwd = get_tpar("grid.lwd", tpar_list = tpars))
gnx = NA
} else if (!any(c(par("xlog"), type == "boxplot"))) {
xg = if (!inherits(x, c("POSIXt", "Date"))) axTicks(side = 1) else axTicksDateTime(side = 1, x = x)
abline(v = xg, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]])
abline(v = xg, col = get_tpar("grid.col", tpar_list = tpars), lty = get_tpar("grid.lty", tpar_list = tpars), lwd = get_tpar("grid.lwd", tpar_list = tpars))
gnx = NA
}
if (!is.null(yaxb)) {
abline(h = yaxb, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]])
abline(h = yaxb, col = get_tpar("grid.col", tpar_list = tpars), lty = get_tpar("grid.lty", tpar_list = tpars), lwd = get_tpar("grid.lwd", tpar_list = tpars))
gny = NA
} else if (!any(c(par("ylog"), type == "boxplot"))) {
yg = if (!inherits(y, c("POSIXt", "Date"))) axTicks(side = 2) else axTicksDateTime(side = 2, x = x)
abline(h = yg, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]])
abline(h = yg, col = get_tpar("grid.col", tpar_list = tpars), lty = get_tpar("grid.lty", tpar_list = tpars), lwd = get_tpar("grid.lwd", tpar_list = tpars))
gny = NA
}
grid(nx = gnx, ny = gny, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]])
grid(nx = gnx, ny = gny, col = get_tpar("grid.col", tpar_list = tpars), lty = get_tpar("grid.lty", tpar_list = tpars), lwd = get_tpar("grid.lwd", tpar_list = tpars))
}
} else {
grid
Expand Down
4 changes: 2 additions & 2 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ tinyplot.default = function(
type = type,
x = x, xmax = xmax, xmin = xmin,
y = y, ymax = ymax, ymin = ymin,
dynmar = dynmar
tpars = tpars
),
list = list(
add = add,
Expand All @@ -1254,7 +1254,7 @@ tinyplot.default = function(
type = type,
x = datapoints$x, xmax = datapoints$xmax, xmin = datapoints$xmin,
y = datapoints$y, ymax = datapoints$ymax, ymin = datapoints$ymin,
dynmar = get_tpar("dynmar") # https://github.com/grantmcdermott/tinyplot/issues/474
tpars = tpar() # https://github.com/grantmcdermott/tinyplot/issues/474
),
getNamespace("tinyplot")
)
Expand Down
6 changes: 4 additions & 2 deletions R/tinytheme.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@
#' tinytheme(thm)
#' tinyplot(
#' I(Sepal.Length*1e4) ~ Petal.Length | Species, facet = "by", data = iris,
#' main = "Demonstration of tinyplot themes",
#' sub = paste0('tinytheme("', thm, '")')
#' yaxl = ",",
#' main = paste0('tinytheme("', thm, '")'),
#' sub = "A subtitle"
#' )
#' box("outer", lty = 2)
#' }
#'
#' # Reset
Expand Down
5 changes: 3 additions & 2 deletions R/tpar.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ tpar = function(..., hook = FALSE) {


# Two levels of priority: .tpar[["name"]] -> par("name")
get_tpar = function(opts, default = NULL) {
get_tpar = function(opts, default = NULL, tpar_list = NULL) {
if (is.null(tpar_list)) tpar_list = .tpar
# parameter priority
# .tpar[["name"]] -> par("name")
for (o in opts) {
tp = .tpar[[o]]
tp = tpar_list[[o]]
if (!is.null(tp)) {
return(tp)
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"cex_fct_adj",
"dots",
"draw",
"dynmar",
"facet_bg",
"facet_border",
"facet_col",
Expand All @@ -43,6 +42,7 @@
"oyaxis",
"ribbon.alpha",
"split_data",
"tpars",
"type",
"x",
"xaxl",
Expand Down
2 changes: 1 addition & 1 deletion man/facet.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/tinytheme.Rd

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